Regex unexpected token

kosnkov picture kosnkov · Mar 18, 2013 · Viewed 9.3k times · Source

When I add this regex into validation engine I get a javascript error: "unexpected token", it seems that the regex is wrong because it is underline with red, why?

"time1":{    
   "regex": ^([0-9]|0[0-9]|1[0-3]|2[0-3]):[0-5][0-9]$,
   "alertText": "* Invalid Time"
}

Answer

Denys Séguret picture Denys Séguret · Mar 18, 2013

Replace

   "regex": ^([0-9]|0[0-9]|1[0-3]|2[0-3]):[0-5][0-9]$,

with

   "regex": /^([0-9]|0[0-9]|1[0-3]|2[0-3]):[0-5][0-9]$/,

See the syntax of regex literals.