Date regex
Regex for ISO 8601 dates (YYYY-MM-DD) with month 01–12 and day 01–31, plus DD/MM/YYYY and MM/DD/YYYY variants.
Pattern
/^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/Matches
2026-09-271999-12-312024-02-29
Doesn't match
2026-13-012026-9-72026-02-3227/09/2026
Alternative: DD/MM/YYYY (or DD.MM.YYYY)
^(0[1-9]|[12]\d|3[01])[\/.](0[1-9]|1[0-2])[\/.](\d{4})$Notes
- A regex checks ranges per field but not the calendar: 2026-02-31 still passes. Parse the captured groups and check with a real date library.
- Swap the first two groups of the DD/MM pattern for US MM/DD/YYYY.
Code
JavaScript
const re = /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
re.test(value); // true or falsePython
import re
bool(re.fullmatch(r'(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])', value))Try it on your own input
The live tester adds the g and m flags so every line is checked separately.
Questions
Can a regex check leap years?
Technically yes, but the pattern becomes unreadable. Match the shape with regex, then validate the date with code.
More patterns
Email regexPhone number regexURL regexIP address regexTime regex (24-hour and 12-hour)UUID regexHex color regexPassword regex