Class: DeviseTokenAuthEmailValidator

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

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.validate?(email) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/validators/devise_token_auth_email_validator.rb', line 7

def validate?(email)
  email =~ EMAIL_REGEXP
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



12
13
14
15
16
# File 'app/validators/devise_token_auth_email_validator.rb', line 12

def validate_each(record, attribute, value)
  unless DeviseTokenAuthEmailValidator.validate?(value)
    record.errors.add(attribute, email_invalid_message)
  end
end