UTC Offset regex validation

I was working on validating UTC Offset values in a javascript application and came up with this regex to do the job. What do you think?

//see http://en.wikipedia.org/wiki/List_of_UTC_time_offsets for list of valid positive and negative offsets
var positiveOffset = /^[+]?([0-9].?[0]?[0]?|1[0-4].?[0]?[0]?|[3,4,5,6,9,10,11].30|[5,8].45|12.45)$/g;
var negativeOffset = /^[-]([0-9].?[0]?[0]?|1[0-2].?[0]?[0]?|[3,4,9].30)$/g;
var GMT = /^0.?[0]?[0]?$/g;
if(!positiveOffset.test(value) && !negativeOffset.test(data.value) && !GMT.test(value)) {
    //show error
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s