Class: ActiveModel::Validations::EmailValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::EmailValidator
- Defined in:
- lib/validate_email.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ EmailValidator
constructor
A new instance of EmailValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ EmailValidator
Returns a new instance of EmailValidator.
10 11 12 13 |
# File 'lib/validate_email.rb', line 10 def initialize() .reverse_merge!(:message => :email) super() end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/validate_email.rb', line 15 def validate_each(record, attribute, value) begin mail = Mail::Address.new(value) unless mail.address == value && mail.domain.split(".").length > 1 record.errors.add(attribute, [:message]) end rescue record.errors.add(attribute, [:message]) end end |