respect-validation/docs/rules/Each.md

55 lines
1.2 KiB
Markdown
Raw Normal View History

2015-01-30 09:40:06 +01:00
# Each
- `Each(Validatable $rule)`
2015-01-30 09:40:06 +01:00
Validates whether each value in the input is valid according to another rule.
2015-01-30 09:40:06 +01:00
```php
2015-10-18 03:44:47 +02:00
$releaseDates = [
2015-01-30 09:40:06 +01:00
'validation' => '2010-01-01',
'template' => '2011-01-01',
'relational' => '2011-02-05',
2015-10-18 03:44:47 +02:00
];
2015-01-30 09:40:06 +01:00
v::each(v::dateTime())->validate($releaseDates); // true
2015-01-30 09:40:06 +01:00
```
You can also validate array keys combining this rule with [Call](Call.md):
```php
v::call('array_keys', v::each(v::stringType()))->validate($releaseDates); // true
```
This rule will not validate values that are not iterable, to have a more detailed
error message, add [IterableType](IterableType.md) to your chain, for example.
If the input is empty this rule will consider the value as valid, you use
[NotEmpty](NotEmpty.md) if convenient:
```php
v::each(v::dateTime())->validate([]); // true
v::notEmpty()->each(v::dateTime())->validate([]); // false
```
2015-01-30 09:40:06 +01:00
## Categorization
- Arrays
- Nesting
## Changelog
Version | Description
--------|-------------
2.0.0 | Remove support for key validation
0.3.9 | Created
***
2015-01-30 09:40:06 +01:00
See also:
- [ArrayVal](ArrayVal.md)
- [Call](Call.md)
- [IterableType](IterableType.md)
- [Key](Key.md)
2018-12-11 13:31:50 +01:00
- [NotEmpty](NotEmpty.md)
- [Unique](Unique.md)