$validate = Validate::make([
'name|名称' => 'require|chinese',
'email' => 'email'
]);
$validate->extend([
'chinese' => function ($value){
return preg_match('/[\x7f-\xff]/', $value)? true : ':attribute 必须是中文';
},
'isBankSN' => function($value){
return preg_match('/^(\d{16}|\d{19})$/', $value)? true : ':attribute 必须是银行卡号';
},
'is_uuid' =>function($value){
return preg_match('/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/', $value)? true : ':attribute UUID格式不正确';
},
]);而为具体的验证场景或者数据表定义好验证器类,这种方法,如果字段不一致,我需要定义很多验证器类,这样也很繁琐,能不能在项目中扩展内置规则,在需要的地方简单的调用? 最佳答案