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.
^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/Flags: none
Open in the testerWhat 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.
| Input | Result | Why |
|---|---|---|
| 2026-09-27 | Passes | the everyday form |
| 2024-02-29 | Passes | a real leap day |
| 1999-12-31 | Passes | upper bounds of month and day |
| 2026-13-01 | Fails | month 13 |
| 2026-00-10 | Fails | month 00 |
| 2026-01-32 | Fails | day 32 |
| 2026-9-7 | Fails | not zero-padded |
| 27/09/2026 | Fails | day-first with slashes |
| 2026-09-27T10:00:00Z | Fails | a 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.
| Input | Result | Why |
|---|---|---|
| 2026-02-31 | Passes | February has no 31st |
| 2023-02-29 | Passes | 2023 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
- Email address
- URL
- UUID
- IPv4 address
- Hex color
- 24-hour time
- Semantic version
- URL slug
- Phone number (E.164)
- US ZIP code
- MAC address
Or open the regex tester empty and bring your own pattern.