Class: OmgValidator::Validators::EmailValidator

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

Overview

Checks whether input is a valid email address

Matches:

[email protected], [email protected], [email protected]

Does not match:

mail@[email protected], domain.com

Examples:

validates :email, email: true

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/omg_validator/validators/email_validator.rb', line 14

def validate_each(record, attribute, value)
  return nil if value.blank?
  reg = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+$/
  unless reg.match(value)
    record.errors[attribute] = "must be a valid email address"
  end
end