日期正则表达式

问题描述:

我正在使用日期字段检查器,但我想将正则表达式从DD-MM-YYYY更改为DD/MM/YYYY,但似乎无法正常工作.

I'm using a date field checker but I want to change the regex from DD-MM-YYYY to DD/MM/YYYY but I can't seem to get it working..

这是代码段:

"date": {
  "regex": "/^[0-9]{1,2}\-\[0-9]{1,2}\-\[0-9]{4}$/",
  "alertText": "* Invalid date, must be in DD/MM/YYYY format"
},

我敢肯定这很简单,但是我对正则表达式一无所知.我已经尝试过:

I'm sure it's quite simple but I have no idea about regex.. I've tried:

/^[0-9]{1,2}\/\[0-9]{1,2}\/\[0-9]{4}$/

/^[0-9]{1,2}\\/\\[0-9]{1,2}\\/\\[0-9]{4}$/

但是他们都不适合我.

o = 

{

    "date": {
      "regex": /^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/,
      "alertText": "* Invalid date, must be in DD/MM/YYYY format"
    }

}

o.date['regex'].test('02/12/2008')//true
o.date['regex'].test('2009-02-02')// false
o.date['regex'].test('03-04-2009')// false