@@ -489,7 +489,7 @@ $v = Validation::make($_POST,[
489489<a name =" built-in-filters " ></a >
490490## 内置的过滤器
491491
492- > 一些 php 内置的函数可直接使用。 e.g ` trim|ucfirst ` ` json_decode `
492+ > 一些 php 内置的函数可直接使用。 e.g ` trim|ucfirst ` ` json_decode ` ` md5 `
493493
494494过滤器 | 说明 | 示例
495495-------|-------------|------------
@@ -507,6 +507,7 @@ $v = Validation::make($_POST,[
507507` timestamp/strToTime ` | 字符串日期转换时间戳 | ` ['pulishedAt', 'number', 'filter' => 'strToTime'], `
508508` url ` | URL 过滤,移除所有不符合 URL 的字符 | ` ['field', 'url', 'filter' => 'url'], `
509509` str2list/str2array ` | 字符串转数组 ` 'tag0,tag1' -> ['tag0', 'tag1'] ` | ` ['tags', 'strList', 'filter' => 'str2array'], `
510+ ` unique ` | 去除数组中的重复值(by ` array_unique() ` ) | ` ['tagIds', 'intList', 'filter' => 'unique'], `
510511` email ` | email 过滤,移除所有不符合 email 的字符 | ` ['field', 'email', 'filter' => 'email'], `
511512` encoded ` | 去除 URL 编码不需要的字符,与 ` urlencode() ` 函数很类似 | ` ['imgUrl', 'url', 'filter' => 'encoded'], `
512513` clearSpace ` | 清理空格 | ` ['title', 'string', 'filter' => 'clearSpace'], `
@@ -528,7 +529,7 @@ $v = Validation::make($_POST,[
528529` bool/boolean ` | 验证是否是 bool. [ 关于bool值] ( #about-bool-value ) | ` ['open', 'bool'] `
529530` float ` | 验证是否是 float | ` ['price', 'float'] `
530531` string ` | 验证是否是 string. ** 支持长度检查** | ` ['name', 'string'] ` , ` ['name', 'string', 'min'=>4, 'max'=>16] `
531- ` accepted ` | 验证的字段必须为 ` yes/on/1/true ` 这在确认「服务条款」是否同意时有用(from laravel) | ` ['agree', 'accepted'] `
532+ ` accepted ` | 验证的字段必须为 ` yes/on/1/true ` 这在确认「服务条款」是否同意时有用(ref laravel) | ` ['agree', 'accepted'] `
532533` url ` | 验证是否是 url | ` ['myUrl', 'url'] `
533534` email ` | 验证是否是 email | ` ['userEmail', 'email'] `
534535` alpha ` | 验证值是否仅包含字母字符 | ` ['name', 'alpha'] `
@@ -558,18 +559,18 @@ $v = Validation::make($_POST,[
558559` notBe ` | 不能等于给定值 | ` ['status', 'notBe', 0] `
559560` compare/same/equal ` | 字段值比较: 相同 | ` ['passwd', 'compare', 'repasswd'] `
560561` different/notEqual ` | 字段值比较: 不能相同 | ` ['userId', 'notEqual', 'targetId'] `
561- ` requiredIf ` | 指定的其它字段( anotherField )值等于任何一个 ` value ` 时,此字段为 ** 必填** | ` ['city', 'requiredIf', 'myCity', ['chengdu'] ] `
562- ` requiredUnless ` | 指定的其它字段( anotherField )值等于任何一个 ` value ` 时,此字段为 ** 不必填** | ` ['city', 'requiredUnless', 'myCity', ['chengdu'] ] `
563- ` requiredWith ` | 指定的字段中的 _ 任意一个_ 有值且不为空,则此字段为 ** 必填** | ` ['city', 'requiredWith', ['myCity'] ] `
564- ` requiredWithAll ` | 如果指定的 _ 所有字段_ 都有值,则此字段为 ** 必填** | ` ['city', 'requiredWithAll', ['myCity', 'myCity1'] ] `
565- ` requiredWithout ` | 如果缺少 _ 任意一个_ 指定的字段值,则此字段为 ** 必填** | ` ['city', 'requiredWithout', ['myCity', 'myCity1'] ] `
566- ` requiredWithoutAll ` | 如果所有指定的字段 ** 都没有值** ,则此字段为 ** 必填** | ` ['city', 'requiredWithoutAll', ['myCity', 'myCity1'] ] `
562+ ` requiredIf ` | 指定的其它字段( anotherField )值等于任何一个 ` value ` 时,此字段为 ** 必填** (ref laravel) | ` ['city', 'requiredIf', 'myCity', ['chengdu'] ] `
563+ ` requiredUnless ` | 指定的其它字段( anotherField )值等于任何一个 ` value ` 时,此字段为 ** 不必填** (ref laravel) | ` ['city', 'requiredUnless', 'myCity', ['chengdu'] ] `
564+ ` requiredWith ` | 指定的字段中的 _ 任意一个_ 有值且不为空,则此字段为 ** 必填** (ref laravel) | ` ['city', 'requiredWith', ['myCity'] ] `
565+ ` requiredWithAll ` | 如果指定的 _ 所有字段_ 都有值,则此字段为 ** 必填** (ref laravel) | ` ['city', 'requiredWithAll', ['myCity', 'myCity1'] ] `
566+ ` requiredWithout ` | 如果缺少 _ 任意一个_ 指定的字段值,则此字段为 ** 必填** (ref laravel) | ` ['city', 'requiredWithout', ['myCity', 'myCity1'] ] `
567+ ` requiredWithoutAll ` | 如果所有指定的字段 ** 都没有值** ,则此字段为 ** 必填** (ref laravel) | ` ['city', 'requiredWithoutAll', ['myCity', 'myCity1'] ] `
567568` date ` | 验证是否是 date | ` ['publishedAt', 'date'] `
568569` dateFormat ` | 验证是否是 date, 并且是指定的格式 | ` ['publishedAt', 'dateFormat', 'Y-m-d'] `
569570` dateEquals ` | 验证是否是 date, 并且是否是等于给定日期 | ` ['publishedAt', 'dateEquals', '2017-05-12'] `
570- ` beforeDate ` | 验证字段值必须是给定日期之前的值 | ` ['publishedAt', 'beforeDate', '2017-05-12'] `
571- ` beforeOrEqualDate ` | 字段值必须是小于或等于给定日期的值 | ` ['publishedAt', 'beforeOrEqualDate', '2017-05-12'] `
572- ` afterOrEqualDate ` | 字段值必须是大于或等于给定日期的值 | ` ['publishedAt', 'afterOrEqualDate', '2017-05-12'] `
571+ ` beforeDate ` | 验证字段值必须是给定日期之前的值(ref laravel) | ` ['publishedAt', 'beforeDate', '2017-05-12'] `
572+ ` beforeOrEqualDate ` | 字段值必须是小于或等于给定日期的值(ref laravel) | ` ['publishedAt', 'beforeOrEqualDate', '2017-05-12'] `
573+ ` afterOrEqualDate ` | 字段值必须是大于或等于给定日期的值(ref laravel) | ` ['publishedAt', 'afterOrEqualDate', '2017-05-12'] `
573574` afterDate ` | 验证字段值必须是给定日期之前的值 | ` ['publishedAt', 'afterDate', '2017-05-12'] `
574575` json ` | 验证是否是json字符串(默认严格验证,必须以` { ` ` [ ` 开始) | ` ['goods', 'json'] ` ` ['somedata', 'json', false] ` - 非严格,普通字符串` eg 'test' ` 也会通过
575576` file ` | 验证是否是上传的文件 | ` ['upFile', 'file'] `
@@ -594,7 +595,28 @@ $v = Validation::make($_POST,[
594595['createdAt, updatedAt', 'safe']
595596```
596597
597- ### 关于文件验证
598+ ### 一些补充说明
599+
600+ <a name =" about-empty-value " ></a >
601+ #### 关于为空判断
602+
603+ 字段符合下方任一条件时即为「空」
604+
605+ - 该值为 ` null ` .
606+ - 该值为空字符串 ` '' `
607+ - 该值为空数组 ` [] `
608+ - 该值为空对象 -- 空的 ` 可数 ` 对象
609+ - 该值为没有路径的上传文件
610+
611+ <a name =" about-bool-value " ></a >
612+ #### 关于布尔值
613+
614+ 值符合下列的任意一项即认为是为bool值(不区分大小写)
615+
616+ - 是 "1"、"true"、"on" 和 "yes" (` TRUE ` )
617+ - 是 "0"、"false"、"off"、"no" 和 "" (` FALSE ` )
618+
619+ #### 关于文件验证
598620
599621文件验证时注意要设置文件信息源数据
600622
@@ -609,18 +631,10 @@ $v = Validation::make($_POST, [
609631// ...
610632```
611633
612- ### (注意)一些补充说明
634+ #### 提示和注意
613635
614636- ** 请将 ` required* ` 系列规则写在规则列表的最前面**
615- - 关于为空判断:字段符合下方任一条件时即为「空」<a name =" about-empty-value " ></a >
616- - 该值为 ` null ` .
617- - 该值为空字符串 ` '' `
618- - 该值为空数组 ` [] `
619- - 该值为空对象 -- 空的 ` 可数 ` 对象
620- - 该值为没有路径的上传文件
621- - 关于布尔值: 值符合下列的任意一项即认为是为bool值<a name =" about-bool-value " ></a >
622- - 是 "1"、"true"、"on" 和 "yes" (` TRUE ` )
623- - 是 "0"、"false"、"off"、"no" 和 "" (` FALSE ` )
637+ - 验证大小范围 ` int ` 是比较大小。 ` string ` 和 ` array ` 是检查长度。大小范围 是包含边界值的
624638- ` size/range ` ` length ` 可以只定义 ` min ` 或者 ` max ` 值
625639- 支持对数组的子级值验证
626640
@@ -639,8 +653,31 @@ $v = Validation::make($_POST, [
639653 ['goods.pear', 'max', 30], //goods 下的 pear 值最大不能超过 30
640654```
641655
642- - ` required* ` 系列规则参考自 laravel
643- - 验证大小范围 ` int ` 是比较大小。 ` string ` 和 ` array ` 是检查长度。大小范围 是包含边界值的
656+ - 支持对数组的子级值进行遍历验证
657+
658+ ``` php
659+ [
660+ 'goods' => [
661+ 'apple' => 34,
662+ 'pear' => 50,
663+ ],
664+ 'users' => [
665+ ['id' => 34, 'name' => 'tom'],
666+ ['id' => 89, 'name' => 'john'],
667+ ]
668+ ]
669+ ```
670+
671+ ``` php
672+ ['goods.*', 'each', 'number'], //goods 下的 每个值 都必须为大于0 的整数
673+ // 写法是等效的
674+ // ['goods', 'each', 'number'], //goods 下的 每个值 都必须为大于0 的整数
675+
676+ // 多维数组
677+ ['users.*.id', 'each', 'required'],
678+ ['users.*.id', 'each', 'number', 'min' => 34],
679+ ['users.*.name', 'each', 'string', 'min' => 5],
680+ ```
644681
645682## 一些关键方法API
646683
0 commit comments