Regex Patterns

Date (YYYY-MM-DD)

Match dates in ISO 8601 YYYY-MM-DD format with basic month and day validation.

What Is This?

This regex pattern matches dates in the ISO 8601 YYYY-MM-DD format. It validates the basic structure: a 4-digit year, a 2-digit month (01-12), and a 2-digit day (01-31). Note that it validates the format but does not check specific month lengths or leap years.

How to Use

1

The Pattern

Use this pattern for validating date input formats in forms and APIs. For full date validation including correct days per month and leap years, combine regex with a date parsing library. The ISO 8601 format is recommended for data interchange because it is locale-independent and sorts correctly as a string.

/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/

Examples

Example

Valid dates by format

Matches:
2024-01-15
2023-12-25
2025-02-28
1999-07-04

Does not match:
2024-13-01
2024-01-32
2024/01/15
Jan 15, 2024
Example

Edge cases

Matches:
2024-01-01
2024-12-31
2024-02-29

Does not match:
2024-00-01
2024-01-00
24-01-15
2024-1-1

Related Entries

More from this reference:

Frequently Asked Questions

Does this validate February 29 correctly?

No. This regex accepts Feb 29 in any year. For full date validation including leap years, use a date library (e.g., JavaScript Date, moment.js, date-fns) after the regex format check.

Why use YYYY-MM-DD format?

ISO 8601 (YYYY-MM-DD) is the international standard date format. It is unambiguous, sorts alphabetically as chronologically, and avoids confusion between US (MM/DD/YYYY) and European (DD/MM/YYYY) formats.