Regex Pattern

Date Format Regex (YYYY-MM-DD)

By Samrat•Last updated: Nov 2026
Regex Pattern
^\d{4}-\d{2}-\d{2}$

Quick answer

This regex validates the structure of a date in YYYY-MM-DD format. It checks for 4 digits, a dash, 2 digits, a dash, and 2 digits.

🛠️ Fix it right here with AI Regex Generator

Need to modify this pattern or generate a new one? Edit the regex below and let our AI help.

AI suggestions can be wrong. Review and test before applying.

Live Regex Tester

Type a string below to see if it matches this pattern.

How it works

\d{4} matches the year. - matches the dash. \d{2} matches the month and day. Note: This only validates the format, not the actual calendar validity (e.g., it will match 2026-99-99).

Code Examples

✅ Correct Usage

// JavaScript
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
console.log(dateRegex.test("2026-11-14")); // true

❌ What NOT to do

// BAD: Accepts invalid formats like 14-11-2026
const badRegex = /^\d{2}-\d{2}-\d{4}$/;

Frequently asked questions

Does this regex check if the date actually exists?

No. Regex only validates format. To check if '2026-02-30' is a real date, you must use a Date library (like date-fns or Python's datetime).

How do I allow DD/MM/YYYY?

Swap the groups: /^\d{2}\/\d{2}\/\d{4}$/

Related Search Terms

date regexregex for dateyyyy-mm-dd regexdate validation regex

Related Regex Patterns

Need a custom regex pattern?

Use the free to describe what you need in plain English.

Want an AI with memory for your project?

MonsterX AI remembers your codebase across chats.