Sha256: 94c4b4625cad1417fb0d4d99a6ed97f62e99184c77a70aeb6d841abf291034d7
Contents?: true
Size: 452 Bytes
Versions: 36
Compression:
Stored size: 452 Bytes
Contents
class Marty::NameValidator < ActiveModel::Validator def validate(entry) raise 'need field option' unless options[:field] field = options[:field].to_sym value = entry.send(field) return if value.nil? # disallow leading, trailing, >1 internal spaces, special chars (|) if value =~ /\A\s|\s\z|\A.*\s\s.*\z|.*\|.*/ entry.errors[field] << I18n.t('activerecord.errors.messages.extraneous_spaces') end end end
Version data entries
36 entries across 36 versions & 1 rubygems