Yii2 注册表单验证规则 手机注册时候使用短信验证码

public function rules()
    {
        return [
            ['username', 'filter', 'filter' => 'trim'],
            ['username', 'required'],
            ['username', 'unique', 'targetClass' => '\common\models\User', 'message' => '该用户名已经被占用.'],
            ['username', 'string', 'min' => 4, 'max' => 12],
            ['username','match','pattern'=>'/^[a-zA-Z0-9_]+$/','message'=>'{attribute}只能由英文字母、数字、下划线组成'],

            ['realname', 'filter', 'filter' => 'trim'],
            ['realname', 'required'],
            ['realname', 'string', 'min' => 2, 'max' => 4],
            ['realname','match','pattern'=>'/^[\x{4e00}-\x{9fa5}]+$/u','message'=>'{attribute}必须为中文汉字'],

            ['organization_name', 'required'],
            ['organization_name', 'filter', 'filter' => 'trim'],
            ['organization_name', 'string', 'min'=>4,'max' => 20],

            ['email', 'required'],
            ['email', 'email'],
            ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => '该电子邮箱已经被占用.'],

            ['mobile', 'required'],
            ['mobile', 'integer'],
            ['mobile','match','pattern'=>'/^1[0-9]{10}$/','message'=>'{attribute}必须为1开头的11位纯数字'],
            ['mobile', 'string', 'min'=>11,'max' => 11],
            ['mobile', 'unique', 'targetClass' => '\common\models\User', 'message' => '该手机号码已经被占用.'],

            ['smsCode', 'required'],
            ['smsCode', 'integer'],
            ['smsCode', 'string', 'min'=>4,'max' => 4],
            //['smsCode', 'required','requiredValue'=>$this->getSmsCode(),'message'=>'手机验证码输入错误'],

            ['password', 'required'],
            ['password', 'string', 'min' => 6,'max' => 16,'message'=>'{attribute}位数为6至16位'],
        ];
    }

 

posted on 2016-02-04 16:44  yhdsir  阅读(1060)  评论(0编辑  收藏  举报

导航