Sha256: f4ecf792a2b6931595a7a4fdf80c8d080bededc2eea458ccf7cd9e07efbe674d
Contents?: true
Size: 830 Bytes
Versions: 6
Compression:
Stored size: 830 Bytes
Contents
class EmailValidator < ActiveModel::EachValidator def validate_each(record,attribute,value) begin m = Mail::Address.new(value) # We must check that value contains a domain and that value is an email address r = m.domain && m.address == value t = m.__send__(:tree) # We need to dig into treetop # A valid domain must have dot_atom_text elements size > 1 # user@localhost is excluded # treetop must respond to domain # We exclude valid email values like <user@localhost.com> # Hence we use m.__send__(tree).domain r &&= (t.domain.dot_atom_text.elements.size > 1) rescue Exception => e r = false end record.errors[attribute] << (options[:message] || I18n.t(:invalid_email, :scope => [:activerecord, :errors, :messages])) unless r end end
Version data entries
6 entries across 6 versions & 2 rubygems