Class: EmailValidator

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

Instance Method Summary collapse

Instance Method Details

#validate_each(model, attribute, value) ⇒ Object



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

def validate_each(model, attribute, value)
  return model.errors.add(attribute, :blank, **options) if value.blank?

  return if value.is_a?(String) && URI::MailTo::EMAIL_REGEXP.match?(value)

  model.errors.add(attribute, :invalid, **options)
end