yii2表单验证方法

白芸资源网公益广告

yii2表单验证方法

return
[
[['username','password','email','phone','images'],'required','message'=>'不能为空'],
//验证唯一性
[['username'], 'unique','targetClass' => 'backendmodelsVerification','message'=>'用户名不能一致'],
//验证长度
['username', 'string', 'min' => 2, 'max' => 8,"tooLong"=>"太长了", "tooShort"=>"太短了"],
//正则验证
['username','match','pattern'=>'/^[a-z]{1,}$/','message'=>'用户名必须为字母'],
['password','match','pattern'=>'/^[0-9]{6,12}$/','message'=>'密码必须是数字,且大于6为小于12位'],
['email', 'unique', 'targetClass' => 'backendmodelsVerification', 'message' => '邮箱名已存在.'],
//邮箱验证
['email','match','pattern'=>'/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/','message'=>'邮箱格式不正确'],
//手机号验证
['phone','match','pattern'=>'/^1[0-9]{10}$/','message'=>'手机号格式不正确'],
 ];
    © 版权声明
    THE END
    本站一切内容不代表本站立场
    赞赏 分享