Class: Challah::EmailValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Challah::EmailValidator
- Defined in:
- lib/challah/validators/email_validator.rb
Overview
Used to validate reasonably-email-looking strings.
Class Method Summary collapse
-
.pattern ⇒ Object
A reasonable-email-looking regexp pattern.
Instance Method Summary collapse
-
#validate_each(record, attribute, value) ⇒ Object
Called automatically by ActiveModel validation..
Class Method Details
.pattern ⇒ Object
A reasonable-email-looking regexp pattern
17 18 19 |
# File 'lib/challah/validators/email_validator.rb', line 17 def self.pattern /\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,}\z/ end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
Called automatically by ActiveModel validation..
10 11 12 13 14 |
# File 'lib/challah/validators/email_validator.rb', line 10 def validate_each(record, attribute, value) unless value =~ EmailValidator.pattern record.errors.add(attribute, [:message] || :invalid_email) end end |