Skip to main content
Data & Formatting · In-Browser Regular Expression Lab

Date Regex — Validate ISO 8601 Calendar Dates (YYYY-MM-DD)

Validates 4-digit year, 2-digit month (01-12), and 2-digit day (01-31) in ISO format.

Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:2026-10-14

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

2026-10-14 Pass
1999-12-31 Pass
2024-02-29 Pass

Expected Invalid Samples (Must Reject)

2026-13-01 Rejected (Pass)
2026-00-15 Rejected (Pass)
2026-04-32 Rejected (Pass)
26-05-2026 Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/;
const text = "2026-10-14";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Validates structural date format with month 1-12 and day 1-31. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
^\d{4}YearFour-digit Gregorian calendar year.
0[1-9]|1[0-2]MonthZero-padded month from 01 to 12.
0[1-9]|[12]\d|3[01]DayZero-padded day of month from 01 to 31.

Frequently Asked Questions

Can regex detect leap years?
Leap year calendar logic is best handled via JavaScript `Date` or `Temporal` APIs alongside regex.
Browse All 40 Patterns