class Challah::EmailValidator
Used to validate reasonably-email-looking strings.
@example Usage
class User < ActiveRecord::Base validates :email, :presence => true, :email => true end
Public Class Methods
pattern()
click to toggle source
A reasonable-email-looking regexp pattern
# File lib/challah/validators/email_validator.rb, line 17 def self.pattern /\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,}\z/ end
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
Called automatically by ActiveModel validation..
# File lib/challah/validators/email_validator.rb, line 10 def validate_each(record, attribute, value) unless value =~ EmailValidator.pattern record.errors.add(attribute, options[:message] || :invalid_email) end end