3

you can at yii2 in the Model Rules enter patterns in passwords ? Tips for a rule that at least one uppercase character and at least one number ? Thanks so much

Rules

['password', 'pattern' => '(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20}'],
Saba
  • 115
  • 1
  • 15
  • rule array misses one argument, it should be `['password', 'match','pattern' => '..']`, I know it's just a typo but for those who copy past like me it will be confusing – temirbek Aug 09 '22 at 05:08

1 Answers1

5

Your case probably does not work because for some reason Yii2 does not recognize \d or \p so you have to write this part manually or find a way around.

I have tested this one:

/^(?=.*[0-9])(?=.*[A-Z])([a-zA-Z0-9]+)$/

This means it will require at least one upper-case letter and at least one digit (lower-case letters are not necessary).

Gynteniuxas
  • 7,035
  • 18
  • 38
  • 54