| 12345678910111213141516171819202122232425262728 |
- <?php
- namespace App\Module\China\Validator;
- use UCore\Validator;
- /**
- * 中文字符,全中文true
- */
- class IsChineseOnlyValidator extends Validator
- {
- public function validate(mixed $str, array $data): bool
- {
- // 正则表达式用于匹配中文字符
- $pattern = '/^[\x{4e00}-\x{9fa5}]+$/u';
- // 使用 preg_match 检查字符串是否完全匹配
- if (preg_match($pattern, $str)) {
- return true;
- } else {
- return false;
- }
- }
- }
|