Class: ActiveModel::Validations::EmailValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::EmailValidator
- Defined in:
- lib/custom_validations/email_validator.rb
Constant Summary collapse
- REGEX =
/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/custom_validations/email_validator.rb', line 9 def validate_each(record, attribute, value) return if value.to_s.blank? # it doesn't validate presence unless value.to_s =~ REGEX record.errors.add(attribute, :email, ) end end |