Ruby on Rails Password Validation

前端 未结 4 786
鱼传尺愫
鱼传尺愫 2020-12-29 08:16

So I have interesting password validation requirements:

  • When a user signs up, I want them to have to type in password and confirm and be between 6..4

4条回答
  •  悲&欢浪女
    2020-12-29 08:54

    The below seem to meet my requirements...I am actually now requiring a confirmation for all users.. (It makes the view cleaner). But on an update I am allowing blanks.

      validates :password, :presence => true,
                           :confirmation => true,
                           :length => {:within => 6..40},
                           :on => :create
      validates :password, :confirmation => true,
                           :length => {:within => 6..40},
                           :allow_blank => true,
                           :on => :update
    

提交回复
热议问题