2

I'm trying to test if passed string is matching the following format (Thu, 08 Dec 2011 18:48:38 GMT), but I really suck in regular expressions. Any suggestions? Thanks.

7elephant
  • 2,839
  • 5
  • 22
  • 17
  • 5
    UTC is a time zone, not a format. – Matt Ball Dec 08 '11 at 18:24
  • 1
    This is similar to: http://stackoverflow.com/q/685377/675590 – Micah Dec 08 '11 at 18:31
  • 1
    @MДΓΓБДLL: True, although "UTC string" does have meaning in the JavaScript arena: [`toUTCString`](http://es5.github.com/#x15.9.5.42) It's not a precise meaning, as it's completely implementation-dependent, but... :-) – T.J. Crowder Dec 08 '11 at 18:33
  • 1
    Does this help? http://dotnetcaffe.blogspot.com/2009/12/javascript-utc-date-format.html – Micah Dec 08 '11 at 18:43

1 Answers1

2

Here's the regular expression to test what you want:

var t = newDate();
/(Mon|Tue|...|Sun)\,\s\d{2}\s(Jan|Feb|...|Dec)\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT/.test(t.toUTCString())

of course you have to replace the ... with the remaining day and month names

haynar
  • 5,961
  • 7
  • 33
  • 53