Class: EffectiveTelValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- EffectiveTelValidator
- Defined in:
- app/validators/effective_tel_validator.rb
Overview
An ActiveRecord validator for any phone field that you would use with effective_tel
validates :phone, effective_tel: true
Constant Summary collapse
- PATTERN =
/\A\(\d{3}\) \d{3}-\d{4}( x\d+)?\Z/
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
8 9 10 11 12 |
# File 'app/validators/effective_tel_validator.rb', line 8 def validate_each(record, attribute, value) if value.present? record.errors.add(attribute, 'is invalid') unless PATTERN =~ value end end |