REGEXVAULTv2.0
Localization/Time Formats
Verified Safe

UTC Offset Regex for Java

/^(?: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 Java. A rigorously tested regex reduces debugging time and protects your application from edge-case failures. The snippet below is ready to drop into your Java project — whether you're validating in a Spring Boot controller, a Jakarta EE service, or a standalone utility class.

Java Implementation

Java
// UTC Offset
// ReDoS-safe | RegexVault — Localization > Time Formats

import java.util.regex.Pattern;

public class UtcOffsetValidator {
    private static final Pattern PATTERN =
        Pattern.compile("^(?:UTC)?([+-])(2[0-3]|[01][0-9]):([0-5][0-9])$|^(?:UTC)?([+-])(14):(00)$|^(?:UTC|Z|0)$");

    public static boolean validate(String input) {
        return PATTERN.matcher(input).matches();
    }

    // Example
    public static void main(String[] args) {
        System.out.println(validate("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 Java developers because critical in Java applications since the JVM regex engine uses backtracking and is susceptible to ReDoS without careful pattern design. 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