Sha256: 04f9b938bb51810bccc1cbf44ad3ccc0db4330b217d2c0a56c3c5e4f92d039b7
Contents?: true
Size: 451 Bytes
Versions: 43
Compression:
Stored size: 451 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
43 entries across 43 versions & 1 rubygems