class PostcodeValidator
Constants
- ADDRESS_PSEUDO_POSTCODES
Public Class Methods
Source
# File app/validators/postcode_validator.rb, line 24 def self.postcode_valid?(postcode) postcode.full_valid? || postcode.to_s.in?(ADDRESS_PSEUDO_POSTCODES) end
Public Instance Methods
Source
# File app/validators/postcode_validator.rb, line 10 def validate_each(record, attribute, value) if value.blank? record.errors.add(attribute, :blank) unless options[:allow_blank] elsif value.nil? record.errors.add(attribute, :blank) unless options[:allow_nil] else postcode = UKPostcode.parse(value.to_s) unless PostcodeValidator.postcode_valid?(postcode) record.errors.add(attribute, "Enter a valid postcode, such as SW1A 1AA") end end end