Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit f35e804

Browse files
committed
Merge pull request #209 from renanliberato/hotfix/171
Added Explode validator documentation
2 parents 9e75f58 + 9507252 commit f35e804

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

doc/book/validators/explode.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Explode Validator
2+
3+
`Zend\Validator\Explode` executes a validator for each item exploded.
4+
5+
## Supported options
6+
7+
The following options are supported for `Zend\Validator\Explode`:
8+
9+
- `valueDelimiter`: Defines the delimiter used to explode the value to an array. It defaults to `,`. If the given value is an array, this option isn't used.
10+
- `validator`: Sets the validator that will be executed on each exploded item.
11+
12+
## Basic usage
13+
14+
To validate if every item in an array is into a certain haystack:
15+
16+
```php
17+
$inArrayValidator = new Zend\Validator\InArray([
18+
'haystack' => [1, 2, 3, 4, 5, 6]
19+
]);
20+
21+
$explodeValidator = new Zend\Validator\Explode([
22+
'validator' => $inArrayValidator
23+
]);
24+
25+
$explodeValidator->isValid([1, 4, 6]); // returns true
26+
$explodeValidator->isValid([1, 4, 6, 8]); // returns false
27+
```
28+
29+
## Exploding strings
30+
31+
To validate if every e-mail in an string is into a certain name list:
32+
33+
```php
34+
$inEmailListValidator = new Zend\Validator\InArray([
35+
36+
]);
37+
38+
$explodeValidator = new Zend\Validator\Explode([
39+
'validator' => $inEmailListValidator,
40+
'valueDelimiter' => ','
41+
]);
42+
43+
$explodeValidator->isValid('[email protected],[email protected]'); // returns true
44+
$explodeValidator->isValid('[email protected],[email protected]'); // returns false
45+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pages:
1717
- "Db\\RecordExists and Db\\NoRecordExists": validators/db.md
1818
- Digits: validators/digits.md
1919
- EmailAddress: validators/email-address.md
20+
- Explode: validators/explode.md
2021
- GreaterThan: validators/greater-than.md
2122
- Hex: validators/hex.md
2223
- Hostname: validators/hostname.md

0 commit comments

Comments
 (0)