实例
<?php namespace app\index\validate; use think\Validate; class User extends Validate { protected $rule = [ 'name' => 'require|max:25', 'password' => 'number', 'email' => 'email' ]; protected $message = [ 'name.require' => '姓名不能为空', 'name.max' => '姓名不能大于25个字符', 'password.number' => '密码必须是数字', 'email' => '邮箱格式错误' ]; }
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php namespace app\index\controller; use think\Collection; use app\validate\User; use think\Validate; class Ver extends Collection { public function demo() { $data =[ 'name' => '张飞', 'password' => '12345678', 'email' => '38746471@qq.com' ]; $validate = new \app\index\validate\User; if (!$validate -> check($data)) { dump($validate -> getError()); }else { return '验证通过'; } } }
运行实例 »
点击 "运行实例" 按钮查看在线实例