?php
namespace app\home\validate;
use think\Validate;
class Test extends Validate
{
protected $rule = [
'name' => 'require|regex:/.{6}/',
'age' => 'number|between:1,120',
'email' => 'email'
];
protected $message = [
'name.require' => 'name不能少',
'name.regex' => 'name不能少于6个字符',
'age.number' => 'age必须是数字',
'age.between' => 'age必须在1到120之间',
'email.email' => 'email格式不对',
];
protected $scene = [
'name_email' => ['name','email'],
];
}
?>
?php
namespace app\home\controller;
use think\Loader;
use think\Controller;
class Index extends Controller
{
public function test(){
$date = [
'name'=>'qw2e',
'email'=>'12313'
];
//$validate = Loader::validate('Test');//使用加载类Loader
$validate = validate('Test');//使用助手函数
$result = $validate->scene('name_email')->check($date);
if(!$result){
dump($validate->getError());
}
}
}