Regex for Dates in YYYY-MM-DD Format
This validates the ISO 8601 calendar date shape: four-digit year, month 01–12, day 01–31, hyphen-separated and zero-padded. What no regex can do is calendar logic — 2026-02-30 has a valid shape but isn't a real date. Validate the shape here, then let your date parser reject impossible days.
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/How it works, token by token
| Token | Meaning |
|---|---|
| ^\d{4} | the year: exactly four digits |
| (0[1-9]|1[0-2]) | the month: 01–09 or 10–12 — zero-padding required |
| (0[1-9]|[12]\d|3[01]) | the day: 01–09, 10–29, or 30–31 |
| $ | end of string — no trailing time part |
What it matches
2026-07-021999-12-312000-01-012026-13-012026-7-202-07-2026Try it live
One candidate per line — the m flag makes the ^ and $ anchors apply to each line. Edit anything; it runs in your browser.
Variations
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?(Z|[+-]\d{2}:\d{2})$full ISO 8601 timestamp with time and zone: 2026-07-02T09:30:00Z^(0[1-9]|[12]\d|3[01])/(0[1-9]|1[0-2])/\d{4}$DD/MM/YYYY — the European slash formatLanguage notes
- After the shape check, parse for real: new Date(s) in JS accepts YYYY-MM-DD directly; datetime.date.fromisoformat(s) in Python raises on impossible dates like Feb 30.
Frequently asked questions
Does this pattern reject February 30th?
No — 2026-02-30 matches because 30 is a valid day token. Regex checks shape, not the calendar. Combine it with your language's date parser, which will throw on impossible dates, including leap-year rules.
Why require zero-padding?
ISO 8601 mandates it, and it keeps string sorting equal to date sorting — 2026-07-02 sorts correctly between 2026-06-30 and 2026-08-01, which unpadded dates don't.
Building something custom? The regex tester gives you live match highlighting for any pattern.