Class: PhoneNumberValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- PhoneNumberValidator
- Defined in:
- app/models/phone_number_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'app/models/phone_number_validator.rb', line 2 def validate_each(record, attribute, value) if value.blank? record.errors[attribute] << 'is required' unless [:allow_blank] || [:allow_nil] return end record.errors[attribute] << ([:message] || 'is not a valid phone number') if value.gsub(/[^\d]/, '').length < 10 end |