What Is a Good Regex for YYYY-MM-DD Date Validation?

Pattern: ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$. The ISO 8601 date format YYYY-MM-DD is the international standard. This regex validates the format and constrains months to 01-12 and days to 01-31, but cannot catch semantically invalid dates like February 30. Always combine regex format checks with date parsing.

Breaking Down the Pattern

PartMeaning
^Start of string
\d{4}Four-digit year (0000-9999)
-Literal hyphen separator
(0[1-9]|1[0-2])Month: 01-12
-Literal hyphen separator
(0[1-9]|[12]\d|3[01])$Day: 01-31, end of string

Test Cases

InputMatch?Note
2026-04-11YesValid format
2000-01-01YesValid format
1999-12-31YesValid format
2026-13-01NoMonth 13 does not exist
2026-04-32NoDay 32 does not exist

Usage Examples

JavaScript

const pattern = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
pattern.test('2026-04-11');   // true
pattern.test('2026-13-01');   // false

Python

import re
pattern = r'^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$'
bool(re.match(pattern, '2026-04-11'))  # True
bool(re.match(pattern, '2026-13-01'))  # False

Common Pitfalls

Try It Yourself

Test this regex with our Regex Tester.

Frequently Asked Questions

Can regex validate leap years?

Technically yes, but the regex becomes extremely long and unmaintainable. It is far better to validate the format with regex and then use a date library to check if the date actually exists.

Why use YYYY-MM-DD format?

ISO 8601 (YYYY-MM-DD) is unambiguous, sorts lexicographically, and is the standard in databases, APIs, and international communication. Unlike MM/DD/YYYY or DD/MM/YYYY, it cannot be misinterpreted.

Does this regex handle time zones?

No. This pattern only validates the date portion. For datetime with timezone (e.g., 2026-04-11T10:30:00Z), you need an extended pattern.

Built by Michael Lip. 100% client-side — no data leaves your browser.