Date Regex Tester
Test and validate date format patterns with regular expressions. Handle various date formats including ISO 8601, US, European, and custom formats.
Common Date Formats
| Format | Example | Pattern |
|---|---|---|
| ISO 8601 | 2024-12-25 | \d{4}-\d{2}-\d{2} |
| US | 12/25/2024 | \d{2}/\d{2}/\d{4} |
| European | 25/12/2024 | \d{2}/\d{2}/\d{4} |
| US short | 12/25/24 | \d{2}/\d{2}/\d{2} |
| Written | Dec 25, 2024 | [A-Z][a-z]{2} \d{1,2}, \d{4} |
| ISO datetime | 2024-12-25T14:30:00Z | See below |
Date Patterns
``javascript
// ISO 8601 date
const isoDate = /^\d{4}-\d{2}-\d{2}$/;
// ISO 8601 datetime with timezone
const isoDateTime = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|[+-]\d{2}:\d{2})$/;
// US date format (MM/DD/YYYY)
const usDate = /^\d{2}\/\d{2}\/\d{4}$/;
// Flexible date (accepts /, -, or .)
const flexibleDate = /^\d{2}[-.\/]\d{2}[-.\/]\d{4}$/;
// Date with validation
const strictDate = /^(?:0[1-9]|1[0-2])[-\/](?:0[1-9]|[12]\d|3[01])[-\/]\d{4}$/;
// Test
isoDate.test('2024-12-25'); // true
isoDateTime.test('2024-12-25T14:30:00Z'); // true
usDate.test('12/25/2024'); // true
`
Strict Date Validation
`javascript
// Validate date ranges
function validateDateRegex(format) {
// Month: 01-12
const month = '(?:0[1-9]|1[0-2])';
// Day: 01-31 (doesn't check month-specific)
const day = '(?:0[1-9]|[12]\d|3[01])';
// Year: 1900-2099
const year = '(?:19|20)\d{2}';
const patterns = {
'YYYY-MM-DD': new RegExp(^${year}-${month}-${day}$),
'MM/DD/YYYY': new RegExp(^${month}/${day}/${year}$),
'DD/MM/YYYY': new RegExp(^${day}/${month}/${year}$)
};
return patterns[format];
}
const isoStrict = validateDateRegex('YYYY-MM-DD');
isoStrict.test('2024-12-25'); // true
isoStrict.test('2024-13-25'); // false (month > 12)
isoStrict.test('2024-12-32'); // false (day > 31)
`
Extract Dates from Text
`javascript
// Find various date formats in text
const datePattern = /\b(?:\d{4}[-\/]\d{2}[-\/]\d{2}|\d{2}[-\/]\d{2}[-\/]\d{4}|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]* \d{1,2},? \d{4})\b/gi;
const text = "Meeting on 2024-12-25. Follow up 01/15/2025 or January 20, 2025.";
const dates = text.match(datePattern);
// ["2024-12-25", "01/15/2025", "January 20, 2025"]
`
Date Parsing with Groups
`javascript
// Extract date components
const dateParser = /^(?\d{4})-(?\d{2})-(?\d{2})$/;
const match = '2024-12-25'.match(dateParser);
const { year, month, day } = match.groups;
// year: "2024", month: "12", day: "25"
``