Skip to content

date ​

Validates that a field contains a date (and optionally a time) matching a specified format.

Options ​

OptionTypeDefaultDescription
formatstring"MM/DD/YYYY"Format string using the tokens below
messagestringlocale defaultCustom error message

Format tokens ​

TokenMeaningRange
YYYY4-digit yeare.g. 2025
MMMonth01–12
DDDay01–31
HHHour (24 h)00–23
hhHour (12 h)01–12
mmMinutes00–59
ssSeconds00–59
AAM / PMAM or PM

Any literal character in the format (e.g. /, -, :, ) must appear verbatim in the value.

Playground ​

Valid values ​

ValueFormatNotes
"12/25/2025""MM/DD/YYYY"Default format
"25/12/2025""DD/MM/YYYY"European format
"2025-12-25 14:30""YYYY-MM-DD HH:mm"With 24 h time
"12/25/2025 02:30 PM""MM/DD/YYYY hh:mm A"With 12 h time
"2025-12-25 14:30:59""YYYY-MM-DD HH:mm:ss"With seconds

Invalid values ​

ValueFormatReason
"25/12/2025""MM/DD/YYYY"Day/month swapped
"13/32/2025""MM/DD/YYYY"Month 13 or day 32 do not exist
"2025-12-25""MM/DD/YYYY"Wrong separator
"12/25/2025 25:00""MM/DD/YYYY HH:mm"Hour 25 out of range

Notes ​

  • Empty string ("") always returns valid: true — validators only run on non-empty values. Combine with notEmpty to require a value.
  • Leap years are validated correctly (e.g. 02/29/2024 is valid; 02/29/2023 is not).
  • 12:00 AM = midnight (0 h), 12:00 PM = noon (12 h).

Released under the MIT License.