【问题标题】:Timestamp validation with regex. jQuery UI使用正则表达式验证时间戳。 jQuery 用户界面
【发布时间】:2014-04-25 21:47:45
【问题描述】:

我的目标是使用正则表达式语句使用 Javascript 和 jQuery UI 验证时间戳(格式:mm/dd/yy h:mmt 例如04/25/2014 11:39a):

/^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d[ ]([1-9]|1[0-2])[:]([0-5][0-9])(a|p)$/

我的正则表达式适用于这两个网站上的格式化时间戳:

  1. Rubular
  2. regexpal

但是,当我在小部件工厂中使用带有 regexMatch 的 valid 选项时,它不会将时间戳识别为有效值。

这是我的小部件的对象字面量:

widgetName: 'field',
  widgetOptions: {
    label:    'From',
    code:     'fromFilterValue',
    width: 160,
    required:  true,
    valid: { 
      regexpMatch: [
                    '/^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d[ ]([1-9]|1[0-2])[:]([0-5][0-9])(a|p)$/',
                    { field: '_newValue' }
                  ]
                }
  }

【问题讨论】:

    标签: javascript jquery regex jquery-ui timestamp


    【解决方案1】:

    我的小部件抱怨所有数字的 \d 语法。我用[0-9] 替换了所有\d,效果很好。

    谁能解释为什么\d 不起作用?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-11
      • 2015-07-22
      • 1970-01-01
      • 1970-01-01
      • 2017-10-04
      • 2014-09-14
      • 2012-04-19
      相关资源
      最近更新 更多