Class: PhoneNumberFormatValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PhoneNumberFormatValidator
- Defined in:
- lib/ama_validators/phone_number_format_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(object, attribute, value) ⇒ Object
2 3 4 5 6 |
# File 'lib/ama_validators/phone_number_format_validator.rb', line 2 def validate_each(object, attribute, value) unless value =~ /\A(\+?1( |-)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4})\z/ object.errors[attribute] << ([:message] || "enter a valid 10-digit number (e.g. 587-555-5555)") end end |