Regex Date Format Patterns — ISO, US, EU, and More

💡Regex date patterns match date strings by format, not by calendar validity. To match YYYY-MM-DD: \d{4}-\d{2}-\d{2}. For stricter validation, use month range (0[1-9]|1[0-2]) and day range (0[1-9]|[12]\d|3[01]). Test any date regex live with the Regex Tester.

Pattern Examples

ISO 8601 (YYYY-MM-DD)

❌ Wrong

/\d{4}-\d{2}-\d{2}/ // too loose

✅ Fixed

/^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
// Matches: 2024-01-15
// Rejects: 2024-13-01, 2024-00-15

Month 0[1-9]|1[0-2] allows 01-12. Day 0[1-9]|[12]\d|3[01] allows 01-31.

US format (MM/DD/YYYY)

❌ Wrong

/\d{2}/\d{2}/\d{4}/ // forward slash needs escaping

✅ Fixed

/(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/\d{4}/
// Matches: 01/15/2024

Forward slash / doesn't need escaping in most regex flavors, but \ is safe practice.

European format (DD.MM.YYYY)

❌ Wrong

/\d{2}.\d{2}.\d{4}/ // dot matches any char!

✅ Fixed

/(0[1-9]|[12]\d|3[01])\.(0[1-9]|1[0-2])\.\d{4}/
// Matches: 15.01.2024

Dot . matches any character. Escape it \. to match a literal dot.

Flexible year-month-day with separators

❌ Wrong

/\d{4}.\d{2}.\d{2}/ // allows any separator

✅ Fixed

/\d{4}[-/.\s]\d{2}[-/.\s]\d{2}/
// Matches: 2024-01-15, 2024/01/15, 2024.01.15

Character class [-/.\s] matches common separators. Add or remove as needed.

Test Your Pattern

Real-World Usage

Validate ISO date in form input

const ISO_DATE = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
const valid = ISO_DATE.test('2024-01-15'); // true
const invalid = ISO_DATE.test('2024-13-01'); // false (month 13)

Strict pattern validates month 01-12 and day 01-31.

Extract dates from text

const dates = text.match(/\d{4}-\d{2}-\d{2}/g);
// Finds all YYYY-MM-DD dates in a log file or document

global flag g finds all matches. No anchors needed for extraction (unlike validation).

Accept multiple date formats

const ANY_DATE = /\b(\d{4}[-/]\d{2}[-/]\d{2}|\d{2}[-/]\d{2}[-/]\d{4})\b/;
// Matches: 2024-01-15, 2024/01/15, 15-01-2024

[-/] character class matches both - and / as separators.

Related Guides

Frequently Asked Questions

Does regex validate dates like February 30?

No. Regex can check format and ranges but not calendar logic. Feb 30, April 31, and other invalid dates pass regex validation. Use a date library like date-fns or Temporal for semantic validation.

How do I match a date range with regex?

Regex can't express ranges efficiently. Match the date first, then compare the parsed value numerically. Regex for '2020-2024 dates' gets very complex and fragile.

What is the best way to validate date input in a web form?

Use <input type='date'> for browsers, then validate the value with a date library for server-side. Regex is a useful pre-check but shouldn't be the only validation layer.

All tools run in your browser. Your data never leaves your device.