Class: EmailValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/htcht/cli/rails/templates/api_build_files/email_validator.rb

Constant Summary collapse

VALID_EMAIL_REGEX =
%r(\A[^@]+@(?:[^@]+\.)+[^@.]+\z)

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
# File 'lib/htcht/cli/rails/templates/api_build_files/email_validator.rb', line 4

def validate_each(record, attribute, value)
  unless value =~ VALID_EMAIL_REGEX
    record.errors.add(attribute, error_message)
  end
end