How can I make a rule at Yii Framework to allow only characters a-z, underline and dash in username field?
Thanks
You should be able to use the match
/pattern
rule outlined in the manual:
public function rules() {
return array(
array('username', 'required'),
array(
'username',
'match', 'not' => true, 'pattern' => '/[^a-zA-Z_-]/',
'message' => 'Invalid characters in username.',
),
);
}
This, untested code, will require the username
field to contain data and then validate that it doesn't contain a character not in the accepted-character list (a-z, underscore, and dash).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With