Class: ZipCodeValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ZipCodeValidator
- Defined in:
- app/models/zip_code_validator.rb
Constant Summary collapse
- FORMAT =
/\A\d{5}\z/
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/models/zip_code_validator.rb', line 4 def validate_each(record, attribute, value) if value.blank? record.errors[attribute] << 'is required' unless [:allow_blank] || [:allow_nil] return end record.errors[attribute] << ([:message] || 'must be a 5-digit ZIP code') unless value =~ FORMAT end |