44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace app\admin\validate\school\classes;
|
|
|
|
use think\Validate;
|
|
|
|
class ClassesLib extends Validate
|
|
{
|
|
/**
|
|
* 验证规则
|
|
*/
|
|
protected $rule = [
|
|
// 'title' => 'require|length:1,50|alphaNum',
|
|
'title' => 'require|length:1,50',
|
|
// 'alphaNum' 是自定义的规则,用于过滤中文、数字和拼音字符
|
|
];
|
|
/**
|
|
* 提示消息
|
|
*/
|
|
protected $message = [
|
|
'title.require' => '课程名不能为空',
|
|
'title.length' => '课程名长度必须在1到50之间',
|
|
// 'title.alphaNum' =>'课程名只允许中文、数字和拼音字符'
|
|
];
|
|
/**
|
|
* 验证场景
|
|
*/
|
|
protected $scene = [
|
|
'add' => ["title"],
|
|
'edit' => ["title"],
|
|
];
|
|
|
|
// 自定义验证规则
|
|
protected function alphaNum($value, $rule, $data = [])
|
|
{
|
|
$pattern = '/^[\x{4e00}-\x{9fa5}\d]+$/u'; // 正则表达式,匹配中文和数字
|
|
if (preg_match($pattern, $value)) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|