Correction status:qualified
Teacher's comments:
<?php namespace app\validate; use think\Validate; class User extends Validate { protected $rule = [ 'username'=>'require|length:6,20', 'password'=>'require|length:6,14', 'phone'=>'require|length:11|number', 'email'=>'require|email' ]; protected $message=[ 'username.require'=>'用户名不得为空', 'username.length'=>'用户名长度必须在6-20范围', 'password.require'=>'密码不得为空', 'password.length'=>'密码长度必须在6-20范围', 'phone.require'=>'手机号码不得为空', 'phone.length'=>'手机号码长度必须为11个字符', 'phone.number'=>'手机号码必须为数字', 'email.require'=>'邮箱不得为空', 'email.email'=>'邮箱格式不正确', ]; }
点击 "运行实例" 按钮查看在线实例
<?php namespace app\index\controller; use think\Controller; use app\Validate\User; class Verify extends Controller { public function user() { $data = ['username'=>'zs84534344','password'=>'1me21234ss','phone'=>'13145206627','email'=>'97762821@qq.com']; $Validate = new User(); $res = $Validate->check($data); if (!$res) { return $Validate->getError(); } return 'success'; } }
点击 "运行实例" 按钮查看在线实例