Skip to content

Instantly share code, notes, and snippets.

@jacobbubu
Last active October 10, 2017 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobbubu/5408997 to your computer and use it in GitHub Desktop.
Save jacobbubu/5408997 to your computer and use it in GitHub Desktop.
Regular Expression for UTC time offsets validation
^([+]((14|(14[:]?00))|([0][0-9]|[1][01])|([0][0-9]|[1][01])[:]?[0-5][0-9]))|([-]((12|(12[:]?00))|([0][0-9]|[1][01])|([0][0-9]|[1][01])[:]?[0-5][0-9]))$
The offset from UTC is given in the format ±[hh]:[mm], ±[hh][mm], or ±[hh], for exsamples:
Reference to http://en.wikipedia.org/wiki/Zone.tab.
+14:00
+1200
+12
-11:59
-01
-0200
-1200
Invalidate string:
12
12:59
1300
@kfalconer
Copy link

kfalconer commented Oct 10, 2017

[+-]([01]\d|2[0-4])(:?[0-5]\d)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment