Sha256: 3ceb802dedc49bdb13c1abc0fe1ed805bd463d61a61ee0ced88e90a165f1ed57
Contents?: true
Size: 662 Bytes
Versions: 4
Compression:
Stored size: 662 Bytes
Contents
module OmgValidator module Validators # Checks whether input is a valid postal code or a valid zip code # # validates :zip_code, postal_or_zip_code: true class PostalOrZipCodeValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return nil if value.nil? reg = /(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)/i unless reg.match(value) record.errors[attribute] = "must be a valid postal or zip code" end end end end end ActiveModel::Validations::PostalOrZipCodeValidator = OmgValidator::Validators::PostalOrZipCodeValidator
Version data entries
4 entries across 4 versions & 1 rubygems