DiverseYouthNightSchool/application/admin/validate/school/classes/ClassesLib.php

44 lines
1.0 KiB
PHP
Raw Normal View History

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