class MailValidation::EmailValidator
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
uses the mail gem to validate an email address also requires that the email is present and includes a domain
# 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
Protected Instance Methods
append_error(record, attribute)
click to toggle source
# File lib/mail_validation/email_validator.rb, line 17 def append_error(record, attribute) record.errors.add(attribute, options[:message] || :invalid) end