Sha256: e1cbfa10f8bdd8086c20a913e2f036ad818c260044c7b19a9cf94a044c79a7e1

Contents?: true

Size: 480 Bytes

Versions: 41

Compression:

Stored size: 480 Bytes

Contents

require 'mail'

class EmailValidator < ActiveModel::EachValidator

  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( :invalid, :scope => [:activerecord, :errors, :messages] ) ) unless r
  end

end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
iugusdk-1.0.11 app/validators/email_validator.rb
iugusdk-1.0.10 app/validators/email_validator.rb
iugusdk-1.0.9 app/validators/email_validator.rb
iugusdk-1.0.8 app/validators/email_validator.rb
iugusdk-1.0.7 app/validators/email_validator.rb
iugusdk-1.0.6 app/validators/email_validator.rb
iugusdk-1.0.5 app/validators/email_validator.rb
iugusdk-1.0.4 app/validators/email_validator.rb
iugusdk-1.0.3 app/validators/email_validator.rb
iugusdk-1.0.2 app/validators/email_validator.rb
iugusdk-1.0.1 app/validators/email_validator.rb
iugusdk-1.0.0.alpha.32 app/validators/email_validator.rb
iugusdk-1.0.0.alpha.31 app/validators/email_validator.rb
iugusdk-1.0.0.alpha.30 app/validators/email_validator.rb
iugusdk-1.0.0.alpha.29 app/validators/email_validator.rb
iugusdk-1.0.0.alpha.28 app/validators/email_validator.rb
iugusdk-1.0.0.alpha.27 app/validators/email_validator.rb
iugusdk-1.0.0.alpha.26 app/validators/email_validator.rb
iugusdk-1.0.0.alpha.25 app/validators/email_validator.rb
iugusdk-1.0.0.alpha.24 app/validators/email_validator.rb