Class: ActiveModel::Validations::ZipcodeValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/pathf_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/pathf_validator.rb', line 6

def validate_each(record, attribute, value)
  unless /^[0-9]{5}([- ]?[0-9]{4})?$/.match(value)
    record.errors[attribute] << 'is not properly formatted'
  else
    record.errors[attribute] << 'is not valid' unless GoMaps::Address.new(value).exists?
  end
end