Comprehensive date validation regex patterns for various formats including ISO, US, European, and dotted formats
^\d{4}
4-digit year-\d{2}
2-digit month (01-12)-\d{2}$
2-digit day (01-31)(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)// 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
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")))
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"));
}
}
2024-01-15
ISO Format01/15/2024
US Format15/01/2024
EU Format15.01.2024
Dotted Format2024/01/15
Invalid32/01/2024
Invalid DayValidate 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");
}
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)
);
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;
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
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());
}
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;
}
}
Validate email address format
Validate phone number format
Validate URL format
Validate IP address format