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

Commit 8bdb9db

Browse files
committed
docs: documents Date validator strict mode
1 parent 5dfcb5f commit 8bdb9db

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/book/validators/date.md

+21
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,24 @@ $validator = new Zend\Validator\Date(['format' => 'Y']);
3333
$validator->isValid('2010'); // returns true
3434
$validator->isValid('May'); // returns false
3535
```
36+
37+
## Strict mode
38+
39+
- **Since 2.13.0**
40+
41+
By default, `Zend\Validator\Date` only validates that it can convert the
42+
provided value to a valid `DateTime` value.
43+
44+
If you want to require that the date is specified in a specific format, you can
45+
provide both the [date format](#specifying-a-date-format) and the `strict`
46+
options. In such a scenario, the value must both be covertable to a `DateTime`
47+
value **and** be in the same format as provided to the validator. (Generally,
48+
this will mean the value must be a string.)
49+
50+
```php
51+
$validator = new Zend\Validator\Date(['format' => 'Y-m-d', 'strict' => true]);
52+
53+
$validator->isValid('2010-10-10'); // returns true
54+
$validator->isValid(new DateTime('2010-10-10)); // returns false; value is not a string
55+
$validator->isValid('2010.10.10'); // returns false; format differs
56+
```

0 commit comments

Comments
 (0)