Class: EmailValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/hippo/validators/email.rb

Overview

A custom validator “email”. Doesn’t really validate an email completely It simply asserts that the email string has one (and only one) @ (at symbol). This is mainly to give user feedback and not to assert the e-mail validity.

Constant Summary collapse

REGEX =

Regex originated from the Devise gem

/\A[^@]+@([^@\.]+\.)+[^@\.]+\z/

Instance Method Summary collapse

Instance Method Details

#validate_each(rec, attr, value) ⇒ Object



12
13
14
15
16
# File 'lib/hippo/validators/email.rb', line 12

def validate_each( rec, attr, value)
    unless value.present? && value.match( REGEX )
        rec.errors.add attr, options[:message] || 'does not appear to be a valid email'
    end
end