DevKits

Dates & Times

Match an ISO 8601 date

Validate or extract ISO 8601 dates like 2025-06-15.

Pattern

Regular expression

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

How it works

4-digit year, month (01–12), day (01–31). Does not check for months with 30 vs 31 days, or leap years — for strict validation, parse the date and compare.

Matches

  • 2025-06-15
  • 2000-02-29
  • 1999-12-31

Non-matches

  • 2025-13-01 (bad month)
  • 2025-06-32 (bad day)
  • 25-06-15 (short year)

Language snippets

JavaScript

const re = /\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])/g;

Python

re.findall(r"\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])", text)

Go

re := regexp.MustCompile(`\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])`)

Java

Pattern.compile("\\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\\d|3[01])")

Frequently asked questions

What is the regex for ISO 8601 date?

The pattern \d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]) matches ISO 8601 date. 4-digit year, month (01–12), day (01–31). Does not check for months with 30 vs 31 days, or leap years — for strict validation, parse the date and compare.

What does this ISO 8601 date pattern match?

It matches strings like 2025-06-15, 2000-02-29, 1999-12-31, but rejects 2025-13-01 (bad month), 2025-06-32 (bad day).

How do I use this pattern in JavaScript, Python, Go, Java?

Ready-to-run snippets are provided for JavaScript, Python, Go, Java. Copy the one for your language from the Language snippets section — each wraps the same core pattern in that language's regex API.

Related patterns

Try this pattern in a tool

Try any pattern live in the Regex Tester