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
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
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
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:
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.
UUID v4
Match UUID v4 identifiers with the standard 8-4-4-4-12 hex format and version check.
Base64 Encoded String
Match standard Base64 encoded strings with optional padding.
Time (HH:MM 24-hour)
Match times in 24-hour HH:MM format with valid hour and minute ranges.
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.