JavaScript-compatible regex reference

YYYY-MM-DD Date Regex Pattern & Tester

Validate the common four-digit-year, two-digit-month, two-digit-day shape while constraining months to 01–12 and days to 01–31. The pattern is useful for format validation, but calendar semantics such as February 30 still require a real date parser.

Pattern

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

Flags: none

Live test vectors

Test the ISO date (YYYY-MM-DD) regex

Enter one value per line. Each line is tested against the whole-string pattern using the browser JavaScript RegExp engine.

PASS2026-08-17
PASS2000-01-01
PASS1999-12-31
FAIL2026-8-17
FAIL2026-13-01
FAIL2026-00-10
FAIL17-08-2026

Quick answer

Use regex when you need to enforce the YYYY-MM-DD text shape. Use a date parser after the regex if you must reject impossible calendar dates such as 2026-02-31.

Common use cases

  • CSV and import format checks
  • Form input normalization
  • Log and filename date validation

Pitfalls and limitations

  • !A regex that limits days to 01–31 still cannot know how many days are in a specific month.
  • !Leap-year rules are better handled by a date library or runtime parser.
  • !Do not confuse a date-only format with a complete ISO 8601 timestamp including time and timezone.

Known-valid examples

2026-08-172000-01-011999-12-31

Known-invalid examples

2026-8-172026-13-012026-00-1017-08-2026

Continue testing and debugging

Frequently asked questions

Does this regex reject February 31?

No. It validates the numeric YYYY-MM-DD format and broad month/day ranges. Calendar-validity checks belong in a date parser.

Why require two-digit months and days?

The target format is fixed-width YYYY-MM-DD, so January 5 is written 2026-01-05 rather than 2026-1-5.

Can I use this for full ISO 8601 timestamps?

No. Timestamps add time, optional fractional seconds, and timezone information, so they require a different pattern or, preferably, an ISO date-time parser.