Skip to content

Commit 76e4418

Browse files
Merge pull request #284 from tobiashinz/listContains
List contains
2 parents 89117a9 + f87d5b1 commit 76e4418

32 files changed

+105
-8
lines changed

README.md

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
447465
The `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

972990
You 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) {
9821000
This is useful because such rules can have access to variables
9831001
defined in the scope where the `Validator` lives. The Closure's
9841002
signature is identical to `Validator::addRule` callback's
985-
signature.
1003+
signature.
9861004

9871005
If 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`
9921010
instance.
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:
11551173
6. Push to the branch (`git push origin my-new-feature`)
11561174
7. Create new Pull Request
11571175
8. Pat yourself on the back for being so awesome
1158-

lang/ar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'min' => "يجب ان يكون اعلي من %s",
1212
'max' => "يجب ان يكون اقل من %s",
1313
'in' => "الُمدخل يغير صحيح",
14+
'listContains' => "الُمدخل يغير صحيح",
1415
'notIn' => "الُمدخل يغير صحيح",
1516
'ip' => "رقم الإتصال غير صحيح",
1617
'email' => "البريد الألكتروني غير صحيح",

lang/az.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'length' => "%d qədər uzunluğu olmalıdır",
1111
'min' => "minimum %s qədər olmalıdır",
1212
'max' => "maksimum %s qədər olmalıdır",
13+
'listContains' => "yalnış dəyər ehtiva edir",
1314
'in' => "yalnış dəyər ehtiva edir",
1415
'notIn' => "yalnış dəyər ehtiva edir",
1516
'ip' => "düzgün IP ünvanı deyil",

lang/bg.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'length' => "трябва да бъде %d символа дълго",
1111
'min' => "трябвя да бъде поне %s",
1212
'max' => "трябва да бъде не повече от %s",
13+
'listContains' => "съдържа невалидна стойност",
1314
'in' => "съдържа невалидна стойност",
1415
'notIn' => "съдържа невалидна стойност",
1516
'ip' => "е невалиден IP адрес",

lang/de.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'length' => "kann nicht länger als %d sein",
1111
'min' => "muss größer als %s sein",
1212
'max' => "muss kleiner als %s sein",
13+
'listContains' => "enthält einen ungültigen Wert",
1314
'in' => "enthält einen ungültigen Wert",
1415
'notIn' => "enthält einen ungültigen Wert",
1516
'ip' => "enthält keine gültige IP-Addresse",

lang/el.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'length' => "πρέπει να είναι μεγαλύτερο από %d",
1111
'min' => "πρέπει να είναι τουλάχιστον %s",
1212
'max' => "δεν πρέπει να είναι περισσότερο από %s",
13+
'listContains' => "περιέχει μη έγκυρη τιμή",
1314
'in' => "περιέχει μη έγκυρη τιμή",
1415
'notIn' => "περιέχει μη έγκυρη τιμή",
1516
'ip' => "δεν είναι έγκυρη διεύθυνση IP",

lang/en.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'length' => "must be %d characters long",
1111
'min' => "must be at least %s",
1212
'max' => "must be no more than %s",
13+
'listContains' => "contains invalid value",
1314
'in' => "contains invalid value",
1415
'notIn' => "contains invalid value",
1516
'ip' => "is not a valid IP address",

lang/fi.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'length' => "on lyhyempi kuin %d",
1111
'min' => "ei ole vähintään %s",
1212
'max' => "ei ole enintään %s",
13+
'listContains' => "sisältää virheellisen arvon",
1314
'in' => "sisältää virheellisen arvon",
1415
'notIn' => "sisältää virheellisen arvon",
1516
'ip' => "ei ole oikeanmuotoinen IP-osoite",

lang/fr.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'length' => "doit être plus long que %d",
1111
'min' => "doit être plus grand que %s",
1212
'max' => "doit être plus petit que %s",
13+
'listContains' => "contient une valeur non valide",
1314
'in' => "contient une valeur non valide",
1415
'notIn' => "contient une valeur non valide",
1516
'ip' => "n'est pas une adresse IP valide",

lang/id.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'length' => "harus lebih panjang dari %d",
1111
'min' => "harus lebih besar dari %s",
1212
'max' => "harus kurang dari %s",
13+
'listContains' => "berisi nilai/value yang tidak valid",
1314
'in' => "berisi nilai/value yang tidak valid",
1415
'notIn' => "berisi nilai/value yang tidak valid",
1516
'ip' => "format alamat IP tidak benar",

0 commit comments

Comments
 (0)