Date Regex Patterns

Comprehensive date validation regex patterns for various formats including ISO, US, European, and dotted formats

ISO FormatYYYY-MM-DD
^\d{4}-\d{2}-\d{2}$
US FormatMM/DD/YYYY
^(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/(19|20)\d{2}$
European FormatDD/MM/YYYY
^(0[1-9]|[12]\d|3[01])\/(0[1-9]|1[0-2])\/(19|20)\d{2}$
Dotted FormatDD.MM.YYYY
^(0[1-9]|[12]\d|3[01])\.(0[1-9]|1[0-2])\.(19|20)\d{2}$
Pattern Breakdown

ISO Format (YYYY-MM-DD)

^\d{4}4-digit year
-\d{2}2-digit month (01-12)
-\d{2}$2-digit day (01-31)

US Format (MM/DD/YYYY)

(0[1-9]|1[0-2])Month (01-12)
\/(0[1-9]|[12]\d|3[01])Day (01-31)
\/(19|20)\d{2}Year (1900-2099)
Test Date Format
Code Examples
javascript
// ISO format YYYY-MM-DD
const isoRegex = /^\d{4}-\d{2}-\d{2}$/;
console.log(isoRegex.test("2024-01-15")); // true

// US format MM/DD/YYYY
const usRegex = /^(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/(19|20)\d{2}$/;
console.log(usRegex.test("01/15/2024")); // true
python
import re

# ISO format
iso_pattern = r"^\d{4}-\d{2}-\d{2}$"
print(bool(re.match(iso_pattern, "2024-01-15")))

# US format
us_pattern = r"^(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/(19|20)\d{2}$"
print(bool(re.match(us_pattern, "01/15/2024")))
java
import java.util.regex.*;

public class DateRegex {
    public static void main(String[] args) {
        // ISO format
        String isoRegex = "^\\d{4}-\\d{2}-\\d{2}$";
        System.out.println(Pattern.matches(isoRegex, "2024-01-15"));
        
        // US format
        String usRegex = "^(0[1-9]|1[0-2])\\/(0[1-9]|[12]\\d|3[01])\\/(19|20)\\d{2}$";
        System.out.println(Pattern.matches(usRegex, "01/15/2024"));
    }
}
Test Cases
2024-01-15ISO Format
Valid
01/15/2024US Format
Valid
15/01/2024EU Format
Valid
15.01.2024Dotted Format
Valid
2024/01/15Invalid
Invalid
32/01/2024Invalid Day
Invalid
Common Use Cases

Form Date Validation

Validate date format when users fill out forms to ensure the entered date matches the expected format and avoid data format errors.

// Form date validation
if (!dateRegex.test(userDate)) {
  showError("Please enter correct date format");
}

Data Import and Cleaning

Validate and standardize date formats during bulk data import to ensure data consistency and usability.

// Data cleaning
const validDates = rawData.filter(item =>
  dateRegex.test(item.date)
);

Internationalization Date Handling

Validate and convert date formats according to different regional standards in internationalized applications, supporting multiple date format standards.

// Internationalized date validation
const regex = locale === 'US' ? usDateRegex :
  locale === 'EU' ? euDateRegex : isoDateRegex;
Frequently Asked Questions

Why does date validation always fail?

Date validation usually fails due to format mismatch. Please ensure the date format exactly matches the regular expression, including separators, digits, and order.

Correct formats: 2024-01-15, 01/15/2024, 15.01.2024
Incorrect formats: 2024/1/15, 1-15-24, 15/1/2024

How to validate date validity?

Regular expressions can only validate format, not whether the date actually exists (like February 30th). It's recommended to combine with JavaScript's Date object for complete validation.

// Complete date validation
if (dateRegex.test(dateStr)) {
  const date = new Date(dateStr);
  return !isNaN(date.getTime());
}

How to handle different regional date formats?

Use different regular expressions based on user locale or region settings. You can detect user locale and apply the corresponding date format validation.

// Regional format handling
const getDateRegex = (locale) => {
  switch(locale) {
    case 'US': return usDateRegex;
    case 'EU': return euDateRegex;
    default: return isoDateRegex;
  }
}
Related Regex Patterns

Email Regex

Validate email address format

Phone Number Regex

Validate phone number format

URL Regex

Validate URL format

IP Address Regex

Validate IP address format