Module: EmailValidator::ClassMethods

Includes:
RFC822
Defined in:
lib/email-validator.rb

Constant Summary

Constants included from RFC822

RFC822::EMAIL_ADDRESS_REGEX

Instance Method Summary collapse

Instance Method Details

#validate_email_format(attribute, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/email-validator.rb', line 12

def validate_email_format(attribute, options = {})
  options.reverse_merge! :message => 'is invalid'

  validates_each([attribute], options) do |record, attr, value|
    valid_email = record.send(attr).to_s.match EMAIL_ADDRESS_REGEX
    record.errors.add attr, options[:message] unless valid_email
  end
end