From 8bdb9db06ad5b7111a7a06e3a6e3a63a5ad7b747 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Fri, 27 Dec 2019 22:00:31 -0600 Subject: [PATCH] docs: documents Date validator strict mode --- docs/book/validators/date.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/book/validators/date.md b/docs/book/validators/date.md index 83de95a40..fe484722e 100644 --- a/docs/book/validators/date.md +++ b/docs/book/validators/date.md @@ -33,3 +33,24 @@ $validator = new Zend\Validator\Date(['format' => 'Y']); $validator->isValid('2010'); // returns true $validator->isValid('May'); // returns false ``` + +## Strict mode + +- **Since 2.13.0** + +By default, `Zend\Validator\Date` only validates that it can convert the +provided value to a valid `DateTime` value. + +If you want to require that the date is specified in a specific format, you can +provide both the [date format](#specifying-a-date-format) and the `strict` +options. In such a scenario, the value must both be covertable to a `DateTime` +value **and** be in the same format as provided to the validator. (Generally, +this will mean the value must be a string.) + +```php +$validator = new Zend\Validator\Date(['format' => 'Y-m-d', 'strict' => true]); + +$validator->isValid('2010-10-10'); // returns true +$validator->isValid(new DateTime('2010-10-10)); // returns false; value is not a string +$validator->isValid('2010.10.10'); // returns false; format differs +```