Class: EmailValidator

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

Overview

Simple e-mail format validator

Usage

validates :foo, :email => true

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object

:nodoc:#



9
10
11
12
# File 'lib/custom_validators/email.rb', line 9

def validate_each(record, attribute, value) #:nodoc:#
  record.errors[attribute] << (options[:message] || "is not an email") unless
    value =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
end