class PostalCodeValidator
Constants
- REGEXP
keys are ISO-3366-1 alpha2
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
# File lib/validators/postal_code_validator.rb, line 8 def validate_each record, attribute, value key = (options[:country] || I18n.locale).downcase.to_sym key = :gb if key == :uk # Since it's easy to get this wrong raise ArgumentError, "There is no validation for the country `#{key}'" if REGEXP[key].nil? record.errors.add attribute, (options[:message] || I18n.t('rails_validations.postal_code.invalid')) unless value =~ REGEXP[key] end