0

I want to validate the passwords of users on my website with minimum length of 8 characters, But in these 8 characters i want how many numbers inserted on password, if there are less than 2 numbers in password then it will show that the password is incorrect.?

Example password 1: aCxR2Vgy In correct password

Example password 2: a7x45e7m Correct Password

How do i perform this? any suggestions...

1 Answers1

0

I am assuming your password attribute as password.

Pass this pattern. It will check for minimum 2 numeric digit and password length of 8. You can pass any message there according to your need.

In model, use this line.

['password', 'match', 'pattern'=>"^(?=.*?[0-9]{2}).{8,}$",'message'=>'Your password should contain atleast 2 digit and password length must be of 8'],

For more info, please click Regex Pattern.

Community
  • 1
  • 1
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77