Sha256: d2347a82d198903221a12e33f942f0ba77c8a3e46f1c61da35cab8d73554629c

Contents?: true

Size: 391 Bytes

Versions: 5

Compression:

Stored size: 391 Bytes

Contents

class PostalCodeFormatValidator < ActiveModel::EachValidator
  def validate_each(object, attribute, value)
    unless value =~ /\A(\d{5}((-|\s)\d{4})?)|([txTX]\d[abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ]\d)\z/
      object.errors[attribute] << (options[:message] || "enter a valid AB or NT postal code (e.g. T4C 1A5)")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ama_validators-0.0.8 lib/ama_validators/postal_code_format_validator.rb
ama_validators-0.0.7 lib/ama_validators/postal_code_format_validator.rb
ama_validators-0.0.6 lib/ama_validators/postal_code_format_validator.rb
ama_validators-0.0.5 lib/ama_validators/postal_code_format_validator.rb
ama_validators-0.0.4 lib/ama_validators/postal_code_format_validator.rb