Date (YYYY-MM-DD)Regex — Pattern, Examples & Code
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$What it matches / doesn't match
| Matches ✅ | Does not match ❌ |
|---|---|
●2024-01-15 | ●2024-13-01 |
●2000-12-31 | ●2024-01-32 |
●1999-06-01 | ●24-01-15 |
How it works
Matches dates in ISO 8601 YYYY-MM-DD format where month is 01–12 and day is 01–31. It correctly rejects month 13 and day 32, but does not account for month-specific day limits (e.g., February 30). Use a date library for full calendar validation after this initial format check.
Code Usage
JavaScript
const regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
regex.test("2024-01-15"); // truePython
import re
pattern = re.compile(r'^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$')
bool(pattern.match("2024-01-15")) # TrueGo
import "regexp"
r := regexp.MustCompile(`^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$`)
r.MatchString("2024-01-15") // trueNeed a custom regex for a different use case?
Generate a custom regex with AI →FAQ
What does the Date (YYYY-MM-DD) regex pattern match?
Matches dates in ISO 8601 YYYY-MM-DD format where month is 01–12 and day is 01–31. It correctly rejects month 13 and day 32, but does not account for month-specific day limits (e.g., February 30). Use a date library for full calendar validation after this initial format check.
How do I use the Date (YYYY-MM-DD) regex in JavaScript?
const regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/; regex.test("2024-01-15"); // true
Can I use the Date (YYYY-MM-DD) regex in Python?
Yes. import re pattern = re.compile(r'^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$') bool(pattern.match("2024-01-15")) # True
