Module: Clearance::User::Validations
- Defined in:
- lib/clearance/user.rb
Class Method Summary collapse
-
.included(model) ⇒ Object
Hook for validations.
Class Method Details
.included(model) ⇒ Object
Hook for validations.
:email must be present, unique, formatted
If password is required, :password must be present, confirmed
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/clearance/user.rb', line 49 def self.included(model) model.class_eval do validates_presence_of :email, :unless => :email_optional? validates_uniqueness_of :email, :case_sensitive => false, :allow_blank => true validates_format_of :email, :with => %r{^[a-z0-9!#\$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#\$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$}i, :allow_blank => true validates_presence_of :password, :unless => :password_optional? validates_confirmation_of :password end end |