Class: MailValidation::EmailValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- MailValidation::EmailValidator
- Defined in:
- lib/mail_validation/email_validator.rb
Instance Method Summary collapse
-
#validate_each(record, attribute, value) ⇒ Object
uses the mail gem to validate an email address also requires that the email is present and includes a domain.
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
uses the mail gem to validate an email address also requires that the email is present and includes a domain
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/mail_validation/email_validator.rb', line 5 def validate_each(record, attribute, value) begin address = Mail::Address.new(value) if address.domain.nil? || !address.domain.match(/\.[A-Za-z]+\z/) append_error(record, attribute) end rescue Mail::Field::ParseError => e append_error(record, attribute) end end |