Class: EmailValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/email_validator.rb

Overview

coding: utf-8

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'app/validators/email_validator.rb', line 4

def validate_each(record,attribute,value)
  begin
    m = Mail::Address.new(value)
    r = m.domain && m.address == value
    t = m.__send__(:tree)
    r &&= (t.domain.dot_atom_text.elements.size > 1)
  rescue Exception => e   
    r = false
  end
  record.errors[attribute] << (options[:message] || I18n.t(".contact_form.email_validator.error_message")) unless r
end