Regex to Match Timezone Offsets
Validate timezone offset strings in ISO 8601 format including Z for UTC, and +/-HH:MM format from -14:00 to +14:00. Free online regex pattern tester.
Regular Expression
/^(?:Z|[+-](?:0[0-9]|1[0-4]):[0-5][0-9])$/
Token Breakdown
| Token | Description |
|---|---|
| ^ | Anchors at the start of the string (or line in multiline mode) |
| (?: | Start of non-capturing group |
| Z | Matches the literal character 'Z' |
| | | Alternation — matches the expression before OR after the pipe |
| [+-] | Character class — matches any one of: +- |
| (?: | Start of non-capturing group |
| 0 | Matches the literal character '0' |
| [0-9] | Character class — matches any one of: 0-9 |
| | | Alternation — matches the expression before OR after the pipe |
| 1 | Matches the literal character '1' |
| [0-4] | Character class — matches any one of: 0-4 |
| ) | End of group |
| : | Matches the literal character ':' |
| [0-5] | Character class — matches any one of: 0-5 |
| [0-9] | Character class — matches any one of: 0-9 |
| ) | End of group |
| $ | Anchors at the end of the string (or line in multiline mode) |
Detailed Explanation
This regex validates timezone offset strings as defined in the ISO 8601 standard. Here is the token-by-token breakdown:
^ — Anchors the match at the start of the string.
(?: — Opens a non-capturing group for the two format alternatives.
Z — First alternative: matches the literal Z character representing Coordinated Universal Time (UTC). This is the simplest timezone designator, commonly called Zulu time.
| — Alternation operator.
[+-] — Matches either a plus sign (for offsets east of UTC) or a minus sign (for offsets west of UTC).
(?:0[0-9]|1[0-4]) — A non-capturing group matching the hours portion. 0[0-9] matches hours 00-09, and 1[0-4] matches hours 10-14. The maximum offset is 14 hours, covering all existing time zones including UTC+14:00 used by Line Islands.
: — Matches the literal colon separating hours and minutes.
[0-5][0-9] — Matches the minutes portion from 00 to 59. Most timezone offsets use 00, 30, or 45 for minutes, but this allows any valid minute value.
) — Closes the non-capturing group.
$ — Anchors the match at the end of the string.
No flags are used since this validates a single timezone offset string.
Timezone offsets are essential in datetime handling. Common examples include Z (UTC), +00:00 (also UTC), -05:00 (US Eastern), +05:30 (India), +09:00 (Japan), and +14:00 (Line Islands). This pattern is useful for datetime parsing, timezone conversion tools, and API input validation.
Example Test Strings
| Input | Expected |
|---|---|
| Z | Match |
| +05:30 | Match |
| -08:00 | Match |
| +15:00 | No Match |
| EST | No Match |
| +00:00 | Match |
Try It — Interactive Tester
40 charsFlags: noneMatches: 0Ctrl+Shift+C to copy regex
Related Regex Patterns
Regex to Match ISO 8601 DateTime
/^\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{1,3})?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/
Regex to Match ISO 8601 Duration Format
/^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(?:T(?!$)(\d+H)?(\d+M)?(\d+(?:\.\d+)?S)?)?$/
Regex to Match 24-Hour Time Format
/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/
Regex to Match YYYY-MM-DD Dates
/^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$/