@@ -143,6 +143,7 @@ V::lang('ar');
143143 * ` lengthMax ` - String must be less than given length
144144 * ` min ` - Minimum
145145 * ` max ` - Maximum
146+ * ` listContains ` - Performs in_array check on given array values (the other way round than ` in ` )
146147 * ` in ` - Performs in_array check on given array values
147148 * ` notIn ` - Negation of ` in ` rule (not in array of values)
148149 * ` ip ` - Valid IP address
@@ -443,6 +444,23 @@ $v->rules([
443444$v->validate();
444445```
445446
447+ ## listContains fields usage
448+ The ` listContains ` rule checks that the field is present in a given array of values.
449+ ``` php
450+ $v->rule('listContains', 'color', 'yellow');
451+ ```
452+
453+ Alternate syntax.
454+ ``` php
455+ $v = new Valitron\Validator(['color' => ['blue', 'green', 'red', 'yellow']]);
456+ $v->rules([
457+ 'listContains' => [
458+ ['color', 'yellow']
459+ ]
460+ ]);
461+ $v->validate();
462+ ```
463+
446464## in fields usage
447465The ` in ` rule checks that the field is present in a given array of values.
448466``` php
@@ -970,7 +988,7 @@ Valitron\Validator::addRule('alwaysFail', function($field, $value, array $params
970988```
971989
972990You can also use one-off rules that are only valid for the specified
973- fields.
991+ fields.
974992
975993``` php
976994$v = new Valitron\Validator(array("foo" => "bar"));
@@ -982,12 +1000,12 @@ $v->rule(function($field, $value, $params, $fields) {
9821000This is useful because such rules can have access to variables
9831001defined in the scope where the ` Validator ` lives. The Closure's
9841002signature is identical to ` Validator::addRule ` callback's
985- signature.
1003+ signature.
9861004
9871005If you wish to add your own rules that are not static (i.e.,
988- your rule is not static and available to call ` Validator `
989- instances), you need to use ` Validator::addInstanceRule ` .
990- This rule will take the same parameters as
1006+ your rule is not static and available to call ` Validator `
1007+ instances), you need to use ` Validator::addInstanceRule ` .
1008+ This rule will take the same parameters as
9911009` Validator::addRule ` but it has to be called on a ` Validator `
9921010instance.
9931011
@@ -1067,7 +1085,7 @@ You can also add rules on a per-field basis:
10671085$rules = [
10681086 'required',
10691087 ['lengthMin', 4]
1070- ];
1088+ ];
10711089
10721090$v = new Valitron\Validator(array('foo' => 'bar'));
10731091$v->mapFieldRules('foo', $rules);
@@ -1155,4 +1173,3 @@ before running the tests:
115511736 . Push to the branch (` git push origin my-new-feature ` )
115611747 . Create new Pull Request
115711758 . Pat yourself on the back for being so awesome
1158-
0 commit comments