Date Format Regex
Regex patterns for validating dates in ISO, US, European, and other formats.
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$About this pattern
Date validation with regex can check format but not logical correctness (February 30 passes the format check). The ISO 8601 pattern above validates YYYY-MM-DD with months 01-12 and days 01-31. For US dates (MM/DD/YYYY), swap the groups. For European dates (DD/MM/YYYY), reverse again. For production systems, parse the date with a date library after format validation to catch impossible dates.
Worked examples
Month and day ranges are enforced, so 2026-13-01 fails — but it cannot know February has no 30th.
Matches
- 2026-08-07
- 1999-12-31
- 2000-01-01
Does not match
- 2026-13-01
- 2026-00-10
- 2026-08-32
- 26-08-07
FAQ
Can regex catch invalid dates like Feb 30?
Not easily. Regex can validate the format (correct number of digits, months 01-12, days 01-31) but cannot know which months have 30 vs 31 days or handle leap years. Use date parsing after regex validation.