From 12604ccd6c0e3171481ea56aff665569fe370931 Mon Sep 17 00:00:00 2001 From: bison <1308362@gmail.com> Date: Fri, 15 Jul 2016 09:29:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E9=AA=8C=E8=AF=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/library/think/Validate.php b/library/think/Validate.php index 5ff0929d..bac3ccaf 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -47,6 +47,10 @@ class Validate 'alphaNum' => ':attribute只能是字母和数字', 'alphaDash' => ':attribute只能是字母、数字和下划线_及破折号-', 'activeUrl' => ':attribute不是有效的域名或者IP', + 'chs' => ':attribute只能是汉字', + 'chsAlpha' => ':attribute只能是汉字、字母', + 'chsAlphaNum'=> ':attribute只能是汉字、字母和数字', + 'chsDash' => ':attribute只能是汉字、字母、数字和下划线_及破折号-', 'url' => ':attribute不是有效的URL地址', 'ip' => ':attribute不是有效的IP地址', 'dateFormat' => ':attribute必须使用日期格式 :rule', @@ -497,6 +501,22 @@ class Validate // 只允许字母、数字和下划线 破折号 $result = $this->regex($value, '/^[A-Za-z0-9\-\_]+$/'); break; + case 'chs': + // 只允许汉字 + $result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}]+$/u'); + break; + case 'chsAlpha': + // 只允许汉字、字母 + $result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z]+$/u'); + break; + case 'chsAlphaNum': + // 只允许汉字、字母和数字 + $result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9]+$/u'); + break; + case 'chsDash': + // 只允许汉字、字母、数字和下划线_及破折号- + $result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-]+$/u/'); + break; case 'activeUrl': // 是否为有效的网址 $result = checkdnsrr($value); From 3387f7389bc4e5f1b30e4d648861950acf0b19be Mon Sep 17 00:00:00 2001 From: bison <1308362@gmail.com> Date: Fri, 15 Jul 2016 09:49:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=9C=A8=E9=AA=8C=E8=AF=81=E5=99=A8?= =?UTF-8?q?=E4=B8=AD=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=92=88=E5=AF=B9=E4=B8=AD?= =?UTF-8?q?=E6=96=87=E5=AD=97=E7=AC=A6=E6=A3=80=E6=B5=8B=E7=9A=84=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Validate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Validate.php b/library/think/Validate.php index f12e6c4f..552494d0 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -534,7 +534,7 @@ class Validate break; case 'chsDash': // 只允许汉字、字母、数字和下划线_及破折号- - $result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-]+$/u/'); + $result = $this->regex($value, '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-]+$/u'); break; case 'activeUrl': // 是否为有效的网址