Skip to content

Commit 0232052

Browse files
committed
update ...
1 parent ffbdfdd commit 0232052

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ $v = Validation::make($_POST,[
445445
446446
### `isEmpty` -- 是否为空判断
447447

448-
是否为空判断, 这个判断作为 `skipOnEmpty` 的依据. 默认使用 `ValidatorList::isEmpty` 来判断.
448+
是否为空判断, 这个判断作为 `skipOnEmpty` 的依据. 默认使用 `Validators::isEmpty` 来判断.
449449

450450
你也可以自定义判断规则:
451451

@@ -634,6 +634,7 @@ $v = Validation::make($_POST, [
634634
#### 提示和注意
635635

636636
- **请将 `required*` 系列规则写在规则列表的最前面**
637+
- 规则上都支持添加过滤器
637638
- 验证大小范围 `int` 是比较大小。 `string``array` 是检查长度。大小范围 是包含边界值的
638639
- `size/range` `length` 可以只定义 `min` 或者 `max`
639640
- 支持对数组的子级值验证
@@ -679,7 +680,7 @@ $v = Validation::make($_POST, [
679680
['users.*.name', 'each', 'string', 'min' => 5],
680681
```
681682

682-
> 对于带有通配符`*`的字段, 添加过滤器是无效的
683+
- 对于带有通配符`*`的字段, 添加过滤器是无效的
683684

684685
## 一些关键方法API
685686

src/ValidationTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function validate(array $onlyChecked = null, $stopOnError = null)
174174
$fields = \is_string($fields) ? Helper::explode($fields) : (array)$fields;
175175
$validator = $rule[0];
176176

177-
// 如何判断属性为空 默认使用 ValidatorList::isEmpty(). 也可自定义
177+
// 如何判断属性为空 默认使用 Validators::isEmpty(). 也可自定义
178178
$isEmpty = [Validators::class, 'isEmpty'];
179179
if (!empty($rule['isEmpty']) && (\is_string($rule['isEmpty']) || $rule['isEmpty'] instanceof \Closure)) {
180180
$isEmpty = $rule['isEmpty'];

src/Validators.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Inhere\Validate\Utils\Helper;
1313

1414
/**
15-
* Class ValidatorList
15+
* Class Validators
1616
* @package Inhere\Validate
1717
*/
1818
class Validators
@@ -983,11 +983,7 @@ public static function dateFormat($val, $format = 'Y-m-d')
983983
}
984984

985985
// 校验日期的格式有效性
986-
if (date($format, $unixTime) === $val) {
987-
return true;
988-
}
989-
990-
return false;
986+
return date($format, $unixTime) === $val;
991987
}
992988

993989
/**

tests/ValidatorsTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,13 @@ public function testDate()
358358
$this->assertTrue(Validators::date(170526));
359359
$this->assertTrue(Validators::date('20170526'));
360360
}
361+
362+
public function testDateFormat()
363+
{
364+
$this->assertFalse(Validators::dateFormat('hello'));
365+
// $t = strtotime('20170526');
366+
// var_dump($t, time(), date('ymd', $t));
367+
$this->assertFalse(Validators::dateFormat('170526', 'ymd'));
368+
$this->assertTrue(Validators::dateFormat('20170526', 'Ymd'));
369+
}
361370
}

0 commit comments

Comments
 (0)