Back to Validation

Date

docs/validators/Date.md

3.1.13.1 KB
Original Source
<!-- SPDX-License-Identifier: MIT SPDX-FileCopyrightText: (c) Respect Project Contributors SPDX-FileContributor: Alexandre Gomes Gaigalas <[email protected]> SPDX-FileContributor: Henrique Moody <[email protected]> -->

Date

  • Date()
  • Date(string $format)

Validates if input is a date. The $format argument should be in accordance to PHP's date() function, but only those are allowed:

FormatDescriptionValues
dDay of the month, 2 digits with leading zeros01 to 31
jDay of the month without leading zeros1 to 31
SEnglish ordinal suffix for the day of the month, 2 charactersst, nd, rd or th
FA full textual representation of a month, such as January or MarchJanuary to December
mNumeric representation of a month, with leading zeros01 to 12
MA short textual representation of a month, three lettersJan to Dec
nNumeric representation of a month, without leading zeros1 to 12
YA full numeric representation of a year, 4 digitsExamples: 1988 or 2017
yA two digit representation of a yearExamples: 88 or 17

When a $format is not given its default value is Y-m-d.

php
v::date()->assert('2017-12-31');
// Validation passes successfully

v::date()->assert('2020-02-29');
// Validation passes successfully

v::date()->assert('2019-02-29');
// → "2019-02-29" must be a date in the "2005-12-30" format

v::date('m/d/y')->assert('12/31/17');
// Validation passes successfully

v::date('F jS, Y')->assert('May 1st, 2017');
// Validation passes successfully

v::date('Ydm')->assert(20173112);
// Validation passes successfully

Templates

Date::TEMPLATE_STANDARD

ModeTemplate
default{{subject}} must be a date in the {{sample}} format
inverted{{subject}} must not be a date in the {{sample}} format

Template placeholders

PlaceholderDescription
subjectThe validated input or the custom validator name (if specified).
sample

Categorization

  • Date and Time

Changelog

VersionDescription
3.0.0Templates changed
2.0.0Changed to only validate dates
0.3.9Created as Date

See Also