Class: EmailValidator

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

Constant Summary collapse

EMAIL_REGEX =
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
# File 'app/validators/email_validator.rb', line 4

def validate_each(record, attribute, value)
  unless value =~ EMAIL_REGEX
    record.errors.add(attribute, :invalid, **{ value: value }.merge!(options))
  end
end