Skip to content

date

Validates that a field contains a date matching a specified format.

Options

OptionTypeDefaultDescription
formatstring"MM/DD/YYYY"Date format using DD (day), MM (month), YYYY (4-digit year)
minstringundefinedMinimum date (same format as format)
maxstringundefinedMaximum date (same format as format)
separatorstringauto-detectedCharacter separating date parts
messagestringlocale defaultCustom error message

Playground

Valid values

ValueNotes
"12/25/2025"MM/DD/YYYY (default format)
"25/12/2025"DD/MM/YYYY (with format: "DD/MM/YYYY")

Invalid values

ValueReason
"25/12/2025"Day/month swapped (default MM/DD/YYYY)
"13/32/2025"Month 13 or day 32 do not exist
"2025-12-25"Wrong separator for default format

Notes

  • Empty string ("") always returns valid: true — validators only run on non-empty values. Combine with notEmpty to require a value.
  • Separator is auto-detected from the format string unless explicitly set.
  • Leap years are validated correctly.

Released under the MIT License.