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

Commit

Permalink
docs: documents Date validator strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Dec 28, 2019
1 parent 5dfcb5f commit 8bdb9db
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/book/validators/date.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

0 comments on commit 8bdb9db

Please sign in to comment.