• 欢迎访问春风博客

yii2表单验证方法

运维笔记 xiaogang 7年前 (2017-04-05) 1528次浏览 0个评论
return
[
[['username','password','email','phone','images'],'required','message'=>'不能为空'],
//验证唯一性
[['username'], 'unique','targetClass' => '\backend\models\Verification','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' => '\backend\models\Verification', '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'=>'手机号格式不正确'],
 ];

ChunBlog.Com , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:yii2表单验证方法
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址