Skip to content

Regex for Date (MM/DD/YYYY) — Pattern Explained with Examples

DodaTech Updated 2026-06-20 2 min read

In this tutorial, you'll learn about Regex for Date (MM/DD/YYYY). We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

This regex validates dates in the US MM/DD/YYYY format. It checks that the month is 01–12, the day is 01–31, and the year is four digits, all separated by forward slashes. This pattern is commonly used in North American web forms, document processing, and data exchange systems.

The Pattern

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

Pattern Breakdown

Part Meaning
^ Start of string
(0[1-9]\|1[0-2]) Month: 01–09 or 10–12
\/ Escaped forward slash separator
(0[1-9]\|[12]\d\|3[01]) Day: 01–09, 10–29, or 30–31
\/ Escaped forward slash separator
\d{4} Exactly four digits (year)
$ End of string

Matches

  • 01/15/2024
  • 12/31/1999
  • 06/01/2023
  • 02/28/2000
  • 07/04/2024

Does NOT Match

  • 13/01/2024 — month 13 is invalid
  • 01/32/2024 — day 32 is invalid
  • 1/1/2024 — missing leading zeros
  • 2024/01/15 — wrong order (YYYY/MM/DD)
  • 01-15-2024 — hyphens instead of slashes
  • 00/01/2024 — month 00 is invalid
  • 01/01/24 — year is only 2 digits

Language Examples

JavaScript

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

console.log(dateRegex.test('01/15/2024'));  // true
console.log(dateRegex.test('13/01/2024'));  // false
console.log(dateRegex.test('01/32/2024'));  // false

// Extract month, day, year
const match = '12/25/2023'.match(dateRegex);
if (match) {
  console.log(`Month: ${match[1]}, Day: ${match[2]}, Year: ${match[3]}`);
}

Python

import re

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

print(bool(re.match(date_regex, '01/15/2024')))  # True
print(bool(re.match(date_regex, '13/01/2024')))  # False

# Extract parts
match = re.match(date_regex, '07/04/2024')
if match:
    month, day, year = match.groups()
    print(f'{month}/{day}/{year}')

Common Pitfalls

  1. Slash escaping in regex — The / character must be escaped as \/ inside a regex literal. Alternatively, use a different delimiter or construct the regex with new RegExp().

  2. DD/MM vs MM/DD confusion — Users from outside the US often expect DD/MM/YYYY. Make sure your user interface clarifies the expected format.

  3. February 30 passes — Like the YYYY-MM-DD pattern, this regex does not validate calendar logic. 02/30/2024 passes but is not a real date.

  4. Leading zeros matter1/1/2024 fails because single-digit months and days are not matched. Decide whether to accept them with an alternative pattern.

Real-World Use Cases

  • US-based web forms — Standard date input for addresses, billing, and shipping information
  • Document processing — Extracting dates from US government or business documents
  • Data Migration — Converting legacy MM/DD/YYYY data into ISO 8601 for database storage

FAQ

{{< faq-item "How do I make the slashes optional?">}}

Replace \/ with [-/.] to accept hyphens, slashes, or dots as separators. For example: /^(0[1-9]|1[0-2])[-/](0[1-9]|[12]\d|3[01])[-/]\d{4}$/. {{< /faq-item>}}

{{< faq-item "Can I validate that the date is not in the future?">}}

The regex only validates format, not calendar logic or date ranges. After regex validation, parse the date (e.g., new Date() in JS or datetime.datetime.strptime() in Python) and compare against the current date. {{< /faq-item>}}

  • Regex for Date (YYYY-MM-DD)
  • Regex for ISO 8601 Date/Time
  • Regex for Time (HH:MM)

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro