Sha256: e2b033ba6fddc0fdc39f20524fd77624c48f6e1aee6b37c21eb8b97cf05200d4

Contents?: true

Size: 290 Bytes

Versions: 2

Compression:

Stored size: 290 Bytes

Contents

class ZipCodeValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    record.errors.add(attribute, :invalid) unless valid_zip_code?(value)
  end

  private

  def valid_zip_code?(zip_code)
    (zip_code =~ /(\A\d{5}\Z)|(\A\d{5}-\d{4}\Z)/).present?
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
missing_validators-2.3.0 lib/missing_validators/validators/zip_code_validator.rb
missing_validators-2.2.0 lib/missing_validators/validators/zip_code_validator.rb