From 4b898eded86c037c36c698a2bcea498524ffb1e0 Mon Sep 17 00:00:00 2001 From: erzh Date: Mon, 18 Sep 2017 10:51:19 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20bug:=E8=A7=A3=E5=86=B3=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=B5=8B=E8=AF=95=E6=9C=89=E6=9C=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E4=B8=8B=E6=A0=87=E7=9A=84=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=AF=BC=E8=87=B4=E4=B8=8D=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 +-- lib/Validator.php | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index c4dc14d..6507e02 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,7 @@ { "name" : "windwork/util", "description" : "windwork util component,Windwork 工具组件", - "version" : "0.6.0", - "time" : "2017-06-28 18:30:00", + "version" : "0.6.1", "require" : { "php" : ">=5.5.0" }, diff --git a/lib/Validator.php b/lib/Validator.php index 5605a03..b983dad 100644 --- a/lib/Validator.php +++ b/lib/Validator.php @@ -53,21 +53,21 @@ public function validate(array $data, array $rules, $firstErrBreak = false) { $this->errors = []; foreach ($rules as $key => $fieldRule) { + // 待验证字符串 + $string = @$data[$key]; + // 为空并且允许为空则不检查 - if(empty($data[$key]) && !array_key_exists('required', $fieldRule)) { + if(empty($string) && !array_key_exists('required', $fieldRule)) { continue; } - // 待验证字符串 - $string = $data[$key]; - foreach ($fieldRule as $method => $msg) { $method = trim($method); // 自定义正则,下标第一个字符不是字母 // 自定义格式必须是以正则匹配规则作为下标,提示消息作为值 if (preg_match("/[^a-z]/i", $method[0])) { - if(!preg_match($method, $data[$key])) { + if(!preg_match($method, $string)) { $this->errors[] = $msg; }