Match and validate ISO 8601 date format (YYYY-MM-DD) using regex. Includes month and day range validation.
/\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])/g| Token | Meaning |
|---|---|
\d{4} | Exactly 4 digits for the year |
- | Literal dash separator |
(?:0[1-9]|1[0-2]) | Month: 01-09 or 10-12 |
- | Literal dash separator |
(?:0[1-9]|[12]\d|3[01]) | Day: 01-09, 10-29, or 30-31 |
2024-01-15Match2024-12-31Match2025-06-01Match2024-13-01No match2024-00-15No match2024-01-32No matchconst dateRegex = /\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])/g;
const text = "Events on 2024-01-15, 2024-12-31, and invalid 2024-13-01";
const matches = text.match(dateRegex);
console.log(matches); // ["2024-01-15", "2024-12-31"]import re
date_regex = r'\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])'
text = "Events on 2024-01-15, 2024-12-31, and invalid 2024-13-01"
matches = re.findall(date_regex, text)
print(matches) # ['2024-01-15', '2024-12-31']Want to test this pattern with your own data?
Try this pattern in Regex Tester →