Class: EmailValidator

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

Constant Summary collapse

EMAIL_REGEX =
/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
# File 'lib/trax/validators/email_validator.rb', line 4

def validate_each(record, attribute, value)
  unless (value =~ EMAIL_REGEX).present?
    record.errors[attribute] = (options[:message] || "is not a valid email")
  end
  record
end