Class: PhoneValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PhoneValidator
- Defined in:
- lib/phone-validator.rb
Instance Method Summary collapse
-
#validate_each(record, attribute, value) ⇒ Object
validate 10 digit numbers optionally seperated by dashes 123-456-7890 1234567890.
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
validate 10 digit numbers optionally seperated by dashes 123-456-7890 1234567890
7 8 9 10 11 |
# File 'lib/phone-validator.rb', line 7 def validate_each(record, attribute, value) unless value =~ /^[0-9]{3}-?[0-9]{3}-?[0-9]{4}$/ record.errors[attribute] << ([:message] || "is not valid") end end |