Regex unexpected token [closed]
Asked Answered
G

2

6

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"
}
Galen answered 18/3, 2013 at 19:26 Comment(0)
D
15

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.

Dinkins answered 18/3, 2013 at 19:26 Comment(0)
K
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]$/
Klug answered 18/3, 2013 at 19:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.