Class: Ibrain::EmailValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Ibrain::EmailValidator
- Defined in:
- lib/ibrain/core/validators/email.rb
Overview
An ActiveModel Email Validator
Usage
require 'ibrain/core/validators/email'
class Person < ApplicationRecord
validates :email_address, 'ibrain/email' => true
end
Constant Summary collapse
- EMAIL_REGEXP =
URI::MailTo::EMAIL_REGEXP
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
17 18 19 20 21 |
# File 'lib/ibrain/core/validators/email.rb', line 17 def validate_each(record, attribute, value) unless EMAIL_REGEXP.match? value record.errors.add(attribute, :invalid, **{ value: value }.merge!()) end end |