REGEXVAULT
Localization/Time Formats
ReDoS Checked

UTC Offset Regex for JavaScript

/^(?:UTC)?([+-])(2[0-3]|[01][0-9]):([0-5][0-9])$|^(?:UTC)?([+-])(14):(00)$|^(?:UTC|Z|0)$/

All five implementations are free. Switch engines without signing in.

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching utc offset, ported and verified for JavaScript. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.

Javascript Implementation

Javascript
// UTC Offset
// ReDoS-checked | RegexVault — Localization > Time Formats

const utcOffsetRegex = /^(?:UTC)?([+-])(2[0-3]|[01][0-9]):([0-5][0-9])$|^(?:UTC)?([+-])(14):(00)$|^(?:UTC|Z|0)$/;

function validateUtcOffset(input: string): boolean {
  return utcOffsetRegex.test(input);
}

// Example
console.log(validateUtcOffset("UTC")); // true

Test Cases

Matches (Valid)
Rejects (Invalid)
UTC+25:00
Z+05:75
+00:0005:30
+05:30UTC8
-05:00+5:30
+09:30+05:3
-03:30
+14:00
UTC+08:00

When to use this pattern

This pattern is drawn from the Localization > Time Formats category and has been checked for ReDoS risk. That matters for JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

+14:00 (Kiribati/Line Islands) is the most positive real-world offset. Any offset beyond ±14:00 is not a valid IANA timezone — reject it.

Technical Notes

Real-world range: -12:00 (US Minor Outlying Islands) to +14:00 (Line Islands, Kiribati). Half-hour and 45-minute offsets exist. Nepal (+05:45) is the only 45-minute zone in common use.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Submissions join the review queue after automated validation.

Submit a Pattern