T
ToolPrime

Regex for Date (YYYY-MM-DD)

Validates dates in ISO 8601 format with basic month/day range checking.

Pattern

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

Live Tester

Enter a string to test

Examples

2024-01-15
2023-12-31
2000-06-01
2024-13-01
2024-00-15
24-01-15

Pattern Breakdown

^\d{4} — four-digit year

(0[1-9]|1[0-2]) — month 01-12

(0[1-9]|[12]\d|3[01])$ — day 01-31

Code Snippets

Javascript

const regex = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
regex.test("2024-01-15"); // true

Python

import re
pattern = r"^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$"
bool(re.match(pattern, "2024-01-15"))  # True

Php

$pattern = '/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/';
preg_match($pattern, "2024-01-15"); // 1

Related Patterns

Frequently Asked Questions

What is the regex for Date (YYYY-MM-DD)?
The regex pattern for Date (YYYY-MM-DD) is /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/. Validates dates in ISO 8601 format with basic month/day range checking.
How do I use the Date (YYYY-MM-DD) regex in JavaScript?
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the Date (YYYY-MM-DD) pattern match?
It matches strings like 2024-01-15; it rejects strings like 2024-13-01. See the Examples section above for the full list of matching and non-matching cases.

Related Tools