Date/Time
Date DD/MM/YYYY Regex
Most of the world writes dates day first, as in 25/12/2026. This pattern accepts a two-digit day from 01 to 31, a two-digit month from 01 to 12 and a four-digit year, separated by slashes, dashes or dots, and captures each part in its own group. It is a good fit for booking forms, invoice imports and spreadsheet cleanup in the UK, Europe, South Asia, the Middle East and elsewhere. Single-digit days must be zero-padded. The honest limit is that it does not know month lengths, so 31/02/2026 still matches.
Pattern (JavaScript)
/^(0[1-9]|[12][0-9]|3[01])[/.-](0[1-9]|1[0-2])[/.-]([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 one of the characters 12, then a digit OR the character "3", then one of the characters 01), then one of the characters /.-, 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 one of the characters /.-, 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
- ✓ 25/12/2026
- ✓ 01-01-2026
- ✓ 31.03.2025
Does not match
- ✗ 32/01/2026
- ✗ 12/13/2026
- ✗ 1/1/2026
Try it
0 matches (JavaScript engine)
25/12/2026
01-01-2026
31.03.2025
32/01/2026
12/13/2026
1/1/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]|[12][0-9]|3[01])[\/.-](0[1-9]|1[0-2])[\/.-]([0-9]{4})$/g;
const text = "25/12/2026";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(0[1-9]|[12][0-9]|3[01])[/.-](0[1-9]|1[0-2])[/.-]([0-9]{4})$')
text = '25/12/2026'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '#^(0[1-9]|[12][0-9]|3[01])[/.-](0[1-9]|1[0-2])[/.-]([0-9]{4})$#';
$text = '25/12/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]|[12][0-9]|3[01])[/.-](0[1-9]|1[0-2])[/.-]([0-9]{4})$");
String text = "25/12/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]|[12][0-9]|3[01])[/.-](0[1-9]|1[0-2])[/.-]([0-9]{4})$`)
text := "25/12/2026"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(0[1-9]|[12][0-9]|3[01])[/.-](0[1-9]|1[0-2])[/.-]([0-9]{4})$");
var text = "25/12/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]|[12][0-9]|3[01])[/.-](0[1-9]|1[0-2])[/.-]([0-9]{4})$").unwrap();
let text = "25/12/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]|[12][0-9]|3[01])[\/.-](0[1-9]|1[0-2])[\/.-]([0-9]{4})$/
text = '25/12/2026'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- How do I accept single-digit days and months?
- Change 0[1-9] to 0?[1-9] in both the day and month groups. Then 1/1/2026 matches as well as 01/01/2026.
- How can I require the same separator in both places?
- Capture the first separator as ([/.-]) and write \2 in place of the second separator, remembering that the month and year groups shift to 3 and 4. Go and Rust lack backreferences, so check it in code there.
- How do I reject dates like 31/02/2026?
- After matching, build a real date from the captured parts and check that the day, month and year come back unchanged. That handles month lengths and leap years correctly.
Related patterns
- US Date MM/DD/YYYY^(0[1-9]|1[0-2])/(0[1-9]|[12][0-9]|3[01])/([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])$