Class: Apes::Validators::PhoneValidator
- Inherits:
-
BaseValidator
- Object
- ActiveModel::EachValidator
- BaseValidator
- Apes::Validators::PhoneValidator
- Defined in:
- lib/apes/validators.rb
Overview
Validates phones.
Constant Summary collapse
- VALID_REGEX =
The pattern to recognize valid phones.
/^( ((\+|00)\d)? # International prefix ([0-9\-\s\/\(\)]{7,}) # All the rest )$/mx
Instance Method Summary collapse
-
#check_valid?(value) ⇒ Boolean
Checks if the value is valid for this validator.
-
#initialize(options) ⇒ Apes::Validators::PhoneValidator
constructor
Creates a new validator.
Methods inherited from BaseValidator
Constructor Details
#initialize(options) ⇒ Apes::Validators::PhoneValidator
Creates a new validator.
145 146 147 |
# File 'lib/apes/validators.rb', line 145 def initialize() super(.reverse_merge(default_message: "must be a valid phone")) end |
Instance Method Details
#check_valid?(value) ⇒ Boolean
Checks if the value is valid for this validator.
153 154 155 |
# File 'lib/apes/validators.rb', line 153 def check_valid?(value) value.blank? || value =~ VALID_REGEX end |