Regex for Matching a Date (YYYY-MM-DD)
Matches dates in ISO 8601 format.
Published October 10, 2026
This regex matches ISO dates in YYYY-MM-DD format with plausible month and day ranges (but not calendar validity such as Feb 30).
How the pattern works
Breaking the pattern down: \d{4} = year; 0[1-9]|1[0-2] = month 01–12; 0[1-9]|[12]\d|3[01] = day 01–31.
Test your regex against both matching and non-matching inputs; use the Regex tool on this site to experiment live.
Pattern tests
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
✓ '2026-11-12'
✓ '1999-01-31'
✗ '2026-13-01'
✗ '2026-11-32'
Practical examples
The pattern
const re = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/Test it
const re = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
re.test('2026-11-12') // true
re.test('1999-01-31') // true
re.test('2026-13-01') // false
re.test('2026-11-32') // falseIn Python
import re
re.search(r'^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$', text)Common mistakes
- Assuming regex validates calendar dates (Feb 30).
- Locale formats.
- Not using a Date parser for real validation.
Key takeaways
- Anchors (^ and $) make the whole string match instead of a part of it.
- Regex checks format only; verify data separately when it matters.
- Test with valid and invalid samples.
FAQ
Check real validity?
Parse with Date and compare the components.
Where can I test this pattern?
Use the Regex Tester on this site, or regex101.com.