# Regex for Dates in YYYY-MM-DD Format

> ISO date regex for YYYY-MM-DD that checks month 01–12 and day 01–31, with a breakdown and the calendar-logic caveat every date regex has.

```
/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/
```

This validates the ISO 8601 calendar date shape: four-digit year, month 01–12, day 01–31, hyphen-separated and zero-padded. What no regex can do is calendar logic — 2026-02-30 has a valid shape but isn't a real date. Validate the shape here, then let your date parser reject impossible days.

## Token by token

| Token | Meaning |
|---|---|
| `^\d{4}` | the year: exactly four digits |
| `(0[1-9]\|1[0-2])` | the month: 01–09 or 10–12 — zero-padding required |
| `(0[1-9]\|[12]\d\|3[01])` | the day: 01–09, 10–29, or 30–31 |
| `$` | end of string — no trailing time part |

## Examples

- ✓ matches: `2026-07-02`
- ✓ matches: `1999-12-31`
- ✓ matches: `2000-01-01`
- ✗ does not match: `2026-13-01`
- ✗ does not match: `2026-7-2`
- ✗ does not match: `02-07-2026`

## Variations

- `^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T([01]\d|2[0-3]):[0-5]\d:[0-5]\d(\.\d+)?(Z|[+-]\d{2}:\d{2})$` — full ISO 8601 timestamp with time and zone: 2026-07-02T09:30:00Z
- `^(0[1-9]|[12]\d|3[01])/(0[1-9]|1[0-2])/\d{4}$` — DD/MM/YYYY — the European slash format

## Language notes

- After the shape check, parse for real: new Date(s) in JS accepts YYYY-MM-DD directly; datetime.date.fromisoformat(s) in Python raises on impossible dates like Feb 30.

## FAQ

### Does this pattern reject February 30th?

No — 2026-02-30 matches because 30 is a valid day token. Regex checks shape, not the calendar. Combine it with your language's date parser, which will throw on impossible dates, including leap-year rules.

### Why require zero-padding?

ISO 8601 mandates it, and it keeps string sorting equal to date sorting — 2026-07-02 sorts correctly between 2026-06-30 and 2026-08-01, which unpadded dates don't.

## Related patterns

- [Regex for 24-Hour Time (HH:MM)](https://www.devkult.com/regex/time-24h.md)
- [Regex for Phone Number Validation](https://www.devkult.com/regex/phone-number.md)
- [Regex for URL Slug Validation](https://www.devkult.com/regex/slug.md)

Open the interactive page: https://www.devkult.com/regex/date-yyyy-mm-dd