欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

TP自动验证密码范围

程序员文章站 2022-03-08 14:46:15
验证规则 $validate = new Validate( [ 'user_name' => 'require|mobile', 'password' => 'require|max:16|min:8', 'verify_code' => 'require', 'type' => 'number| ......

验证规则

$validate = new validate(
            [
            'user_name' => 'require|mobile',
            'password' => 'require|max:16|min:8',
            'verify_code' => 'require',
            'type' => 'number|between:0,1',
            ],
            ['phone.require' => '手机号必填',
            'phone.mobile' => '手机号格式错误',
            'password.require' => '密码不能为空',
            'password.max' => '密码设置8-16之间',
            'password.min' => '密码设置8-16之间',
            'verify_code.require' => '验证码不能为空',
            'type.between' => '在0和1之间',
            ]
        );

验证方法

        if (!$validate->check($request->post())) {
            $this->apiresult(customerror::operation_succsess, [], $validate->geterror());
        }