Class: ActiveRecord::Validations::CEPValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ActiveRecord::Validations::CEPValidator
- Defined in:
- lib/validates_as_cep.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/validates_as_cep.rb', line 5 def validate_each(record, attribute, value) return if not (value.is_a?(String) ? value : value.to_s).match(/\A(\d{5})([-]{0,1})(\d{3})\Z/).nil? record.errors.add(attribute, I18n.translate('activerecord.errors.messages.invalid', :default => 'invalid'), .merge(:value => value)) end |