我需要字母数字的规则,我需要输入密码,它必须是字母数字。任何人都可以对此有所了解吗?
答案 0 :(得分:1)
在模型类中添加它,
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');
}
}
(或)
你也可以使用this扩展名。