我需要字母数字规则,我需要输入密码,它必须是字母数字。谁能对此有想法?
将此添加到您的模型类中,
public function rules()
{
return array(
array('password', 'compare', 'on'=>"confirmpassword", 'compareAttribute'=>'password'),
array('password','passwordalphanumeric','on'=>'changepassword'),
);
}
// Check password with alphanumeric validation
public function passwordalphanumeric($attribute_name,$params){
if(!empty($this->password)){
if (preg_match('~^[a-z0-9]*[0-9][a-z0-9]*$~i',$this->password)) {
// $subject is alphanumeric and contains at least 1 number
} else { // failed
$this->addError($attribute_name,'Please enter password with digits');
}
}
(或者)
您也可以使用此扩展名。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句