Saba
Saba

Reputation: 115

yii2 password rules pattern

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}'],

Upvotes: 3

Views: 4010

Answers (1)

Gynteniuxas
Gynteniuxas

Reputation: 7103

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).

Upvotes: 5

Related Questions