Module: Devise::Models::Validatable

Defined in:
lib/devise/models/validatable.rb

Overview

Validatable creates all needed validations for a user email and password. It’s optional, given you may want to create the validations by yourself. Automatically validate if the email is present, unique and it’s format is valid. Also tests presence of password, confirmation and length

Constant Summary collapse

EMAIL_REGEX =

Email regex used to validate email formats. Retrieved from authlogic.

/\A[\w\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)\z/i

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/devise/models/validatable.rb', line 13

def self.included(base)
  base.class_eval do

    validates_presence_of     :email
    validates_uniqueness_of   :email, :allow_blank => true
    validates_format_of       :email, :with => EMAIL_REGEX, :allow_blank => true

    validates_presence_of     :password, :if => :password_required?
    validates_confirmation_of :password, :if => :password_required?
    validates_length_of       :password, :within => 6..20, :allow_blank => true, :if => :password_required?
  end
end