添加重复验证和验证码
修改yii2view页面的相关文字显示,增加attributeLabels()方法
public function attributeLabels(){
return [
'username'=>'用户名',
'password'=>'密码',
'email'=>'邮件',
'repassword'=>'重复密码',
'verifyCode'=>'验证码',
];
} 在注册view页面添加代码:
<?=$form->field($model,'repassword')->passwordInput()?>
<?=$form->field($model,'verifyCode')->widget(Captcha::className())?>//use yii\captcha\Captcha
在SighUpForm控制器中添加:
//用户名匹配
['username', 'match','pattern'=>'/^[(\x{4E00}-\x{9FA5})a-zA-Z]+[(\x{4E00}-\x{9FA5})a-zA-Z_\d]*$/u',
'message'=>'用户名由字母,汉字,数字,下划线组成,且不能以数字和下划线开头。'],
//不能为空
[['password','repassword'], 'required'],
//密码是否一致
['repassword','compare','compareAttribute'=>'password','message'=>'两次密码不一致'],
//yii中的验证码
['verifyCode','captcha']
重复验证和验证码
最新推荐文章于 2024-03-17 13:05:34 发布