Incorrect pattern matching in Yii 2
I have a bunch of validation rules in my method rules
and all the errors seem to work, but the problem with this:
['username', 'match', 'pattern' => '/[a-zA-Z0-9_-]+/', 'message' => 'Your username can only contain alphanumeric characters, underscores and dashes.'],
He checks what is the wrong behavior.
Am I doing something wrong here?
+3
source to share
3 answers
This pattern only checks the first character. You need to fix it like below:
['username', 'match', 'pattern' => '/^[a-zA-Z0-9_-]+$/', 'message' => 'Your username can only contain alphanumeric characters, underscores and dashes.'],
To make sure the Yii compliance is working, you can test it by writing @
(for example) as the first character. Then you can see that the validation is working. So the problem is with your template.
+9
source to share