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