zendframework/zend-validator
Powerful validation library from Zend Framework for PHP apps. Provides a wide range of reusable validators, input filtering, and custom rule support with clear error messages. Integrates easily into forms and domain validation workflows.
Zend\Validator\Date allows you to validate if a given value contains a date.
The following options are supported for Zend\Validator\Date:
format: Sets the format which is used to write the date.locale: Sets the locale which will be used to validate date values.The easiest way to validate a date is by using the default date format,
Y-m-d.
$validator = new Zend\Validator\Date();
$validator->isValid('2000-10-10'); // returns true
$validator->isValid('10.10.2000'); // returns false
Zend\Validator\Date also supports custom date formats. When you want to
validate such a date, use the format option. This option accepts any format
allowed by the PHP DateTime::createFromFormat() method.
$validator = new Zend\Validator\Date(['format' => 'Y']);
$validator->isValid('2010'); // returns true
$validator->isValid('May'); // returns false
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 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.)
$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
How can I help you explore Laravel packages today?