5

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"
}
Ben McCormick
  • 25,260
  • 12
  • 52
  • 71
kosnkov
  • 5,609
  • 13
  • 66
  • 107

2 Answers2

14

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.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
3

It should be either string (if you use new RegExp() with it):

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

or regex literal:

"regex": /^([0-9]|0[0-9]|1[0-3]|2[0-3]):[0-5][0-9]$/
VisioN
  • 143,310
  • 32
  • 282
  • 281