T
ToolPrime

Regex for Date (MM/DD/YYYY)

Validates dates in US format MM/DD/YYYY with basic month and day range checking.

Pattern

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

Live Tester

Enter a string to test

Examples

01/15/2024
12/31/2023
06/01/2000
13/01/2024
00/15/2024
1/6/2000

Pattern Breakdown

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

\/ — literal forward slash

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

\/\d{4}$ — slash + four-digit year

Code Snippets

Javascript

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

Python

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

Php

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

Related Patterns

Frequently Asked Questions

What is the regex for Date (MM/DD/YYYY)?
The regex pattern for Date (MM/DD/YYYY) is /^(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/\d{4}$/. Validates dates in US format MM/DD/YYYY with basic month and day range checking.
How do I use the Date (MM/DD/YYYY) 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 (MM/DD/YYYY) pattern match?
It matches strings like 01/15/2024; it rejects strings like 13/01/2024. See the Examples section above for the full list of matching and non-matching cases.

Related Tools