diff --git a/CHANGELOG.md b/CHANGELOG.md index bf9bd34fa..4c85edfe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,9 @@ All notable changes to this project will be documented in this file, in reverse to the IBAN validator for performing SEPA validation against Croatia and San Marino. +- [#209](https://github.com/zendframework/zend-validator/pull/209) adds + documentation for the `Explode` validator. + ### Changed - Nothing. diff --git a/doc/book/validators/explode.md b/doc/book/validators/explode.md new file mode 100644 index 000000000..d314ddd77 --- /dev/null +++ b/doc/book/validators/explode.md @@ -0,0 +1,48 @@ +# Explode Validator + +`Zend\Validator\Explode` executes a validator for each item exploded from an +array. + +## Supported options + +The following options are supported for `Zend\Validator\Explode`: + +- `valueDelimiter`: Defines the delimiter used to explode values from 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. + This may be a validator instance, or a validator service name. + +## Basic usage + +To validate if every item in an array is in a specified 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 a string is contained in a list of names: + +```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 +``` diff --git a/mkdocs.yml b/mkdocs.yml index 277caf7ff..7bc382a3e 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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