Start free · Free tools · Fair usage limits
Browse Tools

Categories

Custom AI Solutions – AI2Flows
LIVE NEWS
Loading latest AI & SEO news…
Home›Tools›Regex Tester›Regex for date (MM/DD/YYYY)
Regex pattern · validation

Regex for date (MM/DD/YYYY)

Regex for date MM/DD/YYYY: a tested pattern with examples, a plain-English breakdown, and code for JavaScript, Python, PHP, Java and Go.

Quick answer

Use /^(?:0[1-9]|1[0-2])\/(?:0[1-9]|[12]\d|3[01])\/\d{4}$/ as a date (MM/DD/YYYY) regex. It matches "11/25/2026" and "01/01/1999", and rejects "13/01/2026" and "11/32/2026". Requires two-digit months and days.

Last updated · Maintained by FreeAIToolz · How we test

/^(?:0[1-9]|1[0-2])\/(?:0[1-9]|[12]\d|3[01])\/\d{4}$/
  • 11/25/2026matches
  • 01/01/1999matches
  • 13/01/2026no match
  • 11/32/2026no match
  • 1/5/2026no match
  • 11-25-2026no match
  • 25/11/2026no match
Open in the full Regex Tester (replace, flags, groups) →

How this regex works

PartMeaning
(?:0[1-9]|1[0-2])month 01–12
\/slash
(?:0[1-9]|[12]\d|3[01])day 01–31
\/\d{4}$slash and four-digit year

Examples

InputResult
11/25/2026✓ Matches
01/01/1999✓ Matches
13/01/2026✗ No match
11/32/2026✗ No match
1/5/2026✗ No match
11-25-2026✗ No match
25/11/2026✗ No match

Every example above is checked automatically in JavaScript and Python each time the site is built.

Limitations and edge cases

Requires two-digit months and days. To also accept 1/5/2026, change 0[1-9] to 0?[1-9] in both places. Impossible dates such as 02/31 still pass.

When to use this pattern

US-formatted date inputs.

Use it in your language

JavaScript

const re = /^(?:0[1-9]|1[0-2])\/(?:0[1-9]|[12]\d|3[01])\/\d{4}$/;
re.test(input); // true or false

Python

import re
pattern = re.compile(r'^(?:0[1-9]|1[0-2])\/(?:0[1-9]|[12]\d|3[01])\/\d{4}$')
bool(pattern.search(value))

PHP

$ok = preg_match('~^(?:0[1-9]|1[0-2])\\/(?:0[1-9]|[12]\\d|3[01])\\/\\d{4}$~', $value) === 1;

Java

Pattern pattern = Pattern.compile("^(?:0[1-9]|1[0-2])\\/(?:0[1-9]|[12]\\d|3[01])\\/\\d{4}$");
boolean ok = pattern.matcher(value).find();

Go

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

More regex patterns

Frequently asked questions

What is the regex for date (MM/DD/YYYY)?
/^(?:0[1-9]|1[0-2])\/(?:0[1-9]|[12]\d|3[01])\/\d{4}$/. Requires two-digit months and days. To also accept 1/5/2026, change 0[1-9] to 0?[1-9] in both places. Impossible dates such as 02/31 still pass.
Which languages does this pattern work in?
It is tested in JavaScript and Python and uses syntax that also works in PHP (PCRE) and Java. It also works in Go’s RE2 engine.
Why does the pattern start with ^ and end with $?
They anchor the match to the whole string, so "abc11/25/2026xyz" cannot pass just because it contains a valid part. To search for matches inside longer text, remove ^ and $ (use \b where word boundaries help) and add the g flag.