Date/Time
US Date MM/DD/YYYY Regex
The United States writes dates month first, as in 12/25/2026, which is easy to confuse with day-first dates used elsewhere. This pattern accepts a two-digit month from 01 to 12, a two-digit day from 01 to 31 and a four-digit year separated by slashes, capturing each part. Because the month comes first, a value such as 25/12/2026 is rejected, which helps detect inputs written in the wrong convention. It suits US tax forms, insurance claims and CSV exports. The honest limit is that dates like 04/05/2026 are valid in both orders, so ambiguity remains.
Pattern (JavaScript)
/^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$/Starts at the start of the line/string, then a group (the character "0", then one of the characters 1-9 OR the character "1", then one of the characters 0-2), then the character "/", then a group (the character "0", then one of the characters 1-9 OR one of the characters 12, then a digit OR the character "3", then one of the characters 01), then the character "/", then a group (a digit, exactly 4 times), then the end of the line/string.
Limit: Checks the format only; it does not check calendar validity like 31 February or leap years.
Examples
Matches
- ✓ 12/25/2026
- ✓ 01/31/2025
- ✓ 07/04/1999
Does not match
- ✗ 25/12/2026
- ✗ 12-25-2026
- ✗ 1/5/2026
Try it
0 matches (JavaScript engine)
12/25/2026
01/31/2025
07/04/1999
25/12/2026
12-25-2026
1/5/2026Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/([0-9]{4})$/g;
const text = "12/25/2026";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$')
text = '12/25/2026'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '#^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$#';
$text = '12/25/2026';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$");
String text = "12/25/2026";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$`)
text := "12/25/2026"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$");
var text = "12/25/2026";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([0-9]{4})$").unwrap();
let text = "12/25/2026";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(0[1-9]|1[0-2])\/(0[1-9]|[12][0-9]|3[01])\/([0-9]{4})$/
text = '12/25/2026'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- How do I accept dates without zero padding?
- Change 0[1-9] to 0?[1-9] in both the month and day groups. Then 1/5/2026 matches as well as 01/05/2026.
- Can this tell whether 04/05/2026 means April or May?
- No regex can, because the string is valid in both conventions. Use clear labels, a date picker or ISO 8601 storage to avoid that ambiguity.
- Why only slashes as separators?
- US dates are almost always written with slashes, and keeping the separator strict reduces confusion with ISO and European forms. Change / to [/-] if you need dashes too.
Related patterns
- Date DD/MM/YYYY^(0[1-9]|[12][0-9]|3[01])[/.-](0[1-9]|1[0-2])[/.-]([0-9]{4})$
- 12-Hour Time with AM/PM^(0?[1-9]|1[0-2]):[0-5][0-9] ?[AaPp][Mm]$
- Date with Month Name^(0?[1-9]|[12][0-9]|3[01]) (?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t|tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?),? ([0-9]{4})$
- ISO 8601 Date (YYYY-MM-DD)^([0-9]{4})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$