class ActiveModelValidators::EmailValidator
Email addresses validator¶ ↑
Constants
- EMAIL_ADDRESS_REGEX
Regular expression used for validation
EMAIL_ADDRESS_REGEX = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
Public Instance Methods
validate_each(record, attr, value)
click to toggle source
-
record
- ActiveRecord model -
attr
- model attribute where email address will be stored -
value
- entered email address
Example¶ ↑
class Model < ActiveRecord::Base validates :my_email, :'active_model_validators/email' => true end
# File lib/active_model_validators/email_validator.rb, line 18 def validate_each(record, attr, value) unless value =~ EMAIL_ADDRESS_REGEX record.errors.add(attr, :invalid) end end