<?php
namespace app\index\controller;
use think\Controller;
use app\validate\Test;
class Id extends Controller
{
//验证器
public function demo()
{
//准备验证的数据
$data =['id'=>10000000000];
$validate = new Test();
if(!$validate->check($data)){
dump($validate->check($data));
dump($validate->getError());
}else{
return 'yes';
}
}
}
<?php
namespace app\validate;
use think\Validate;
class Test extends Validate
{
//验证规则
protected $rule = ['id' =>'number|min:5|max:10'];
//自定义错误信息
protected $message = [
'id.number' => 'id不能为空',
'id.min' => 'id不能小于5位',
'id.max' => 'id不能大于10位',
];
}