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 This Pattern
Pattern
^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$
^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$Usage
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.
Examples
Matches: 2024-01-15, 2023-12-25, 2025-02-28, 1999-07-04. Non-matches: 2024-13-01, 2024-01-32, 2024/01/15, Jan 15, 2024
Matches: 2024-01-01, 2024-12-31, 2024-02-29. Non-matches: 2024-00-01, 2024-01-00, 24-01-15, 2024-1-1
Related Entries
More from this reference:
Email Address Validation
Validate email addresses with a standard pattern covering most common formats.
URL Pattern
Match HTTP and HTTPS URLs with optional port, path, query string, and fragment.
Phone Number (US/International)
Match US and international phone numbers with optional country code and separators.
Credit Card Number (Generic)
Match generic credit card numbers in grouped or continuous 16-digit format.
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.