【问题标题】:Regex unexpected token [closed]正则表达式意外令牌[关闭]
【发布时间】:2013-03-07 06:49:08
【问题描述】:

当我将此正则表达式添加到验证引擎中时,我收到一个 javascript 错误:“意外令牌”,似乎正则表达式错误,因为它带有红色下划线,为什么?

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

【问题讨论】:

    标签: javascript jquery jquery-validation-engine


    【解决方案1】:

    替换

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

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

    the syntax of regex literals

    【讨论】:

      【解决方案2】:

      它应该是字符串(如果你使用new RegExp()):

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

      或正则表达式文字:

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

      【讨论】:

        猜你喜欢
        • 2013-06-01
        • 2021-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多