~/devtools / regex / date
tool::regex-guide

regex date

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

ISO Date Format Validation (YYYY-MM-DD)

ad · 728×90
Regex Pattern
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
Flags:none
Pattern Breakdown
^\d{4}4-digit year (e.g. 2024)
-Literal hyphen separator
(0[1-9]|1[0-2])Month 01–12
-Literal hyphen separator
(0[1-9]|[12]\d|3[01])Day 01–31
$End of string
Matching Examples
2024-01-15
2000-12-31
1999-06-01
Non-Matching Examples
2024-13-01
2024-00-15
24-01-15
2024/01/15

Validates dates in ISO 8601 YYYY-MM-DD format. Months are restricted to 01–12 and days to 01–31. Note: logically invalid dates like February 30 must be caught by additional logic.

Language Usage

JavaScriptUse RegExp object or literal syntax
const pattern = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;

// Test a string
console.log(pattern.test("2024-01-15")); // true
console.log(pattern.test("2024-13-01")); // false

// Match and extract
const result = "2024-01-15".match(pattern);
PythonUse the re module
import re

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

# Test a string
if re.fullmatch(pattern, "2024-01-15"):
    print("Valid")

# Find all matches in text
matches = re.findall(pattern, text)
JavaUse java.util.regex package
import java.util.regex.*;

String pattern = "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$";
Pattern p = Pattern.compile(pattern);

Matcher m = p.matcher("2024-01-15");
boolean isValid = m.matches(); // true

// Find occurrences
Matcher finder = p.matcher(inputText);
while (finder.find()) {
    System.out.println(finder.group());
}

Common Use Cases

  • Validate date input field formats
  • Check date format in API query parameters
  • Pre-process dates before database insertion
  • Clean date columns in CSV files
  • Parse dates from log files

Related Patterns

email/^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-/iphone/^\+?[\d\s\-\(\)]{7,15}$/url/^https?:\/\/[^\s\/$.?#].[^\s]*$/iip-address/^((25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\./
ad · 300×250
Back to Regex Tester
// related tools
Cron Expression Generator
Build and parse cron expressions visually. Generate human-readable descriptions and preview next execution times.
jwt
JWT Decoder
Decode and inspect JWT tokens. View header, payload, and signature details.
Color Converter
Convert colors between HEX, RGB, HSL, and more. Pick colors visually.
ts
Timestamp Converter
Convert Unix timestamps to human-readable dates. Supports ms/s, UTC/local, and relative time.