Class: Apes::Validators::ZipCodeValidator
- Inherits:
-
BaseValidator
- Object
- ActiveModel::EachValidator
- BaseValidator
- Apes::Validators::ZipCodeValidator
- Defined in:
- lib/apes/validators.rb
Overview
Validates ZIP codes.
Constant Summary
- VALID_REGEX =
The pattern to recognized valid ZIP codes.
/^(\d{5}(-\d{1,4})?)$/
Instance Method Summary (collapse)
-
- (Boolean) check_valid?(value)
Checks if the value is valid for this validator.
-
- (Apes::Validators::ZipCodeValidator) initialize(options)
constructor
Creates a new validator.
Methods inherited from BaseValidator
Constructor Details
- (Apes::Validators::ZipCodeValidator) initialize(options)
Creates a new validator.
167 168 169 |
# File 'lib/apes/validators.rb', line 167 def initialize() super(.reverse_merge(default_message: "must be a valid ZIP code")) end |
Instance Method Details
- (Boolean) check_valid?(value)
Checks if the value is valid for this validator.
175 176 177 |
# File 'lib/apes/validators.rb', line 175 def check_valid?(value) value.blank? || value =~ VALID_REGEX end |