How the pattern works
| Part | Meaning |
|---|---|
\d{4}-\d{2}-\d{2} | The date |
T | The literal T separator |
\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)? | Hours and minutes, optional seconds and fractions |
(?:Z|[+-]\d{2}:\d{2}) | Z for UTC, or an offset such as +05:30 |
Code examples
JavaScript
const re = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/;
re.test(value); // true or falsePython
import re
bool(re.fullmatch(r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})', value))PHP
preg_match('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/', $value) === 1;
Notes and limitations
This requires a time zone, which avoids ambiguous timestamps. new Date().toISOString() in JavaScript always produces a matching string. Convert timestamps with the Unix Timestamp Converter.
Regex TesterType a pattern and watch matches highlight live in your test text.
Open the tool Frequently asked questions
What is the regex for ISO 8601 date and time?
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/ — it matches the whole string. See the table above for what each part does.
Which examples match?
Of the examples tested, these match: 2026-10-30T14:30:00Z, 2026-10-30T14:30:00.123+05:30, 2026-10-30T14:30Z. The others don’t.
How do I test this regex?
Click “Open in Regex Tester” — the pattern, flags and sample text load automatically, and matches highlight as you edit.