Regex for a YYYY-MM-DD Date

Regex to match dates in YYYY-MM-DD format, restricting months to 01–12 and days to 01–31. Test it against valid and invalid dates.

Part of the free Regex Tester. Runs in your browser — nothing is uploaded.

Regex for a YYYY-MM-DD Date

This pattern checks the shape of an ISO date and keeps the month between 01 and 12 and the day between 01 and 31. It does not know that February 30 is impossible, so check real validity in code.

Worked example: Valid and invalid ISO dates

Pattern /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/ — test strings

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

2026-01-31
1999-12-01
2026-13-01
2026-00-10
2026-1-5

Result for each line

✓ match     2026-01-31
✓ match     1999-12-01
✗ no match  2026-13-01
✗ no match  2026-00-10
✗ no match  2026-1-5

Practical tip

Combine regex and parsing: use the regex for format, then check new Date(str) round-trips to the same string to reject impossible dates like 2026-02-30.

How to use this Regex Tester

  1. 1Use the live tool above — it runs entirely in your browser and never uploads your data.
  2. 2Paste the sample from the worked example, or use your own input.
  3. 3Copy the result, then adapt the same steps in your editor, script, or pipeline.

Regex for a YYYY-MM-DD Date FAQs

Does this regex reject February 30?

No. It accepts any day 01–31 in any month. Reject impossible calendar dates with a date library after the format check.

How do I allow slashes or dots as separators?

Replace the dash with a character class: [-/.]. Add a backreference if you want the same separator used twice.

More Regex Tester pages

Open the full Regex Tester tool →