REGEXVAULTv2.0
Localization/Time Formats
Verified Safe

UTC Offset Regex for JavaScript

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

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-safe | 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 carries a ReDoS-safe certification. 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. Free submissions join the queue. Priority review available for $15.

Submit a Pattern