^(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/\d{4}$ This pattern validates US-style dates written as MM/DD/YYYY, with the month constrained to 01-12 and the day to 01-31, separated by slashes. It is the common American date format check. Validation patterns answer a yes/no question about an entire input: does this string conform to the expected format? They are anchored with ^ and $ so the whole value must match, and they belong at the edge of your system — form fields, API payloads and import files — where rejecting bad input early prevents downstream errors. A validation regex is a contract check, not a transformation. It needs no special flags. Apply it to the whole input as a format contract. Like the ISO pattern, it does not enforce month-specific day counts or leap years — use a date parser for true validation. It requires zero-padded month/day and a four-digit year; single-digit forms like 1/1/26 are rejected. Ambiguity with DD/MM/YYYY is a real risk — always document which convention your input uses. As with any regular expression, confirm its behavior in your target engine, test boundary and adversarial inputs, and watch for catastrophic backtracking before relying on it in production.
Token-by-token explanation
(0[1-9]|1[0-2]) — month 01-12\/ — literal slash separator(0[1-9]|[12]\d|3[01]) — day 01-31\/ — literal slash\d{4} — four-digit year^...$ — anchors spanning the date
What it matches
12/05/202601/01/200007/04/202612/31/1999 What it does not match
13/05/202612/32/20262026/12/0512-05-20261/1/26 When to use it
Reach for a validation pattern when data crosses a trust boundary: a signup form, an API request body, a CSV import or a configuration value. Run it before any processing so malformed input is rejected with a clear message instead of causing a cryptic failure later. Keep the pattern in one shared place, document the exact format it accepts, and pair it with a real parser when the value has semantics (dates, numbers, addresses) that a shape check alone cannot confirm.
Caveats
- Like the ISO pattern, it does not enforce month-specific day counts or leap years — use a date parser for true validation.
- It requires zero-padded month/day and a four-digit year; single-digit forms like 1/1/26 are rejected.
- Ambiguity with DD/MM/YYYY is a real risk — always document which convention your input uses.
Code examples
const re = /^(0[1-9]|1[0-2])\\/(0[1-9]|[12]\d|3[01])\\/\d{4}$/;
const input = "12/05/2026";
if (re.test(input)) {
// valid: proceed
} else {
// reject with a helpful message
} import re
rx = re.compile(r"^(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/\d{4}$")
value = "12/05/2026"
if rx.fullmatch(value):
pass # valid
else:
raise ValueError("invalid format") import java.util.regex.*;
Pattern p = Pattern.compile("^(0[1-9]|1[0-2])\\/(0[1-9]|[12]\\d|3[01])\\/\\d{4}$");
Matcher m = p.matcher("12/05/2026");
boolean ok = m.matches(); // whole input must conform <?php
$subject = "12/05/2026";
if (preg_match('/^(0[1-9]|1[0-2])\\/(0[1-9]|[12]\d|3[01])\\/\d{4}$/', $subject, $m)) {
// $m[0] is the full match
} How to test it
Before trusting any pattern, test it against three kinds of input: valid examples that must match, invalid examples that must be rejected, and edge cases at the boundaries (empty strings, maximum lengths, unusual separators and Unicode). Paste the expression into a live regex tester with your actual sample data and confirm the highlighted matches are exactly what you intend. Watch for catastrophic backtracking by trying long non-matching inputs, and remember that engine differences (JavaScript, Python, Java, PCRE, Go/RE2) mean a pattern that works in one may fail or behave differently in another — especially lookarounds, which Go's RE2 does not support at all.
Frequently asked questions
How do I accept single-digit months and days?
Relax the branches to (0?[1-9]|1[0-2]) for month and (0?[1-9]|[12]\d|3[01]) for day, and use \d{2,4} for a flexible year if needed.
Is MM/DD/YYYY ambiguous internationally?
Yes — many countries use DD/MM/YYYY, so 03/04 could be March 4 or April 3. Always state the convention explicitly and prefer ISO 8601 for interchange.
Should validation regexes be anchored?
Yes — use ^ and $ (or fullmatch) so the entire input must conform. Without anchors, a valid-looking substring inside garbage would pass, letting malformed data through your validation layer.
What is catastrophic backtracking and how do I avoid it?
Nested quantifiers like (a+)+ can explode exponentially on non-matching input, freezing the engine (ReDoS). Avoid ambiguous nesting, prefer atomic groups or possessive quantifiers where supported, and bound input length.
Try the Regex Tester
Live regex matching with groups, flags and explanations.