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

Commit

Permalink
Merge 9507252 into 010084d
Browse files Browse the repository at this point in the history
  • Loading branch information
renanliberato committed Dec 6, 2017
2 parents 010084d + 9507252 commit 7a8c8bb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions doc/book/validators/explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Explode Validator

`Zend\Validator\Explode` executes a validator for each item exploded.

## Supported options

The following options are supported for `Zend\Validator\Explode`:

- `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.
- `validator`: Sets the validator that will be executed on each exploded item.

## Basic usage

To validate if every item in an array is into a certain haystack:

```php
$inArrayValidator = new Zend\Validator\InArray([
'haystack' => [1, 2, 3, 4, 5, 6]
]);

$explodeValidator = new Zend\Validator\Explode([
'validator' => $inArrayValidator
]);

$explodeValidator->isValid([1, 4, 6]); // returns true
$explodeValidator->isValid([1, 4, 6, 8]); // returns false
```

## Exploding strings

To validate if every e-mail in an string is into a certain name list:

```php
$inEmailListValidator = new Zend\Validator\InArray([
'haystack' => ['joseph@test.com', 'mark@test.com', 'lucia@test.com']
]);

$explodeValidator = new Zend\Validator\Explode([
'validator' => $inEmailListValidator,
'valueDelimiter' => ','
]);

$explodeValidator->isValid('joseph@test.com,mark@test.com'); // returns true
$explodeValidator->isValid('lucia@test.com,maria@test.com'); // returns false
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pages:
- "Db\\RecordExists and Db\\NoRecordExists": validators/db.md
- Digits: validators/digits.md
- EmailAddress: validators/email-address.md
- Explode: validators/explode.md
- GreaterThan: validators/greater-than.md
- Hex: validators/hex.md
- Hostname: validators/hostname.md
Expand Down

0 comments on commit 7a8c8bb

Please sign in to comment.