Class: EmailValidator

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

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



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

def validate_each(record, attribute, value)
  return if value.blank?

  begin
    address = Mail::Address.new(value)
    valid = valid_domain?(address) && value.include?(address.address)
  rescue Mail::Field::ParseError
    valid = false
  end
  record.errors.add(attribute) unless valid
end