ISO 8601 date regex
Matches ISO 8601 dates (`2026-05-15`) and datetimes (`2026-05-15T14:30:00Z`, `2026-05-15T14:30:00.123+05:30`). The time portion is optional so the same pattern works for both date-only and full timestamps.
The pattern
/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?$/Open in testerCaveats
Doesn't validate that the date is real — `2026-02-30` matches the shape. For real validation, parse with `new Date(input)` and check that the result's ISO string round-trips to the original input.
Test strings
A mix of values that should match and values that shouldn't — paste these into the tester to see them light up live.
- 2026-05-15
- 2026-05-15T14:30:00Z
- 2026-05-15T14:30:00.123+05:30
- 2026-02-30
- 2026/05/15
- 15-05-2026