gettoolz.app

ISO 8601 date regex

A calendar date as YYYY-MM-DD: four-digit year, month 01 to 12, day 01 to 31, zero-padded. Copy the pattern, with 5 inputs it accepts and 6 it rejects, each checked against it at build time.

Part of developer tools.

Pattern^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$
JavaScript literal/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/

What the iso 8601 date regex accepts and rejects

Each result below is the output of the pattern itself, run on the input when this page was built — not a claim copied next to it. A wrong verdict stops the build.

Inputs tested against the ISO 8601 date regex
InputResultWhy
2026-09-27Passesthe everyday form
2024-02-29Passesa real leap day
1999-12-31Passesupper bounds of month and day
2026-13-01Failsmonth 13
2026-00-10Failsmonth 00
2026-01-32Failsday 32
2026-9-7Failsnot zero-padded
27/09/2026Failsday-first with slashes
2026-09-27T10:00:00ZFailsa date-time, not a date

What it wrongly lets through

These inputs match although they are not valid — checked the same way, so this list is as true as the one above.

Inputs the ISO 8601 date regex wrongly accepts
InputResultWhy
2026-02-31PassesFebruary has no 31st
2023-02-29Passes2023 is not a leap year

Limits

  • A regex knows the digits, not the calendar: it accepts the 31st of every month and the 29th of February every year. Parse the date and compare it back to the input when the day has to exist.
  • Only the date form is covered. ISO 8601 also has week dates (2026-W39-7), ordinal dates (2026-270) and date-times with offsets, each of which needs its own pattern.

Try it on your own input

Open this pattern in the regex tester with every example above on its own line. The link adds the g and m flags so that ^ and $ hold per line and every line is tested: the highlighted lines are the ones marked as passing here. Paste your own data in place of the examples — it is matched in your browser and never uploaded.

Other common regexes

Or open the regex tester empty and bring your own pattern.