Date Regular Expression

后端 未结 2 350
广开言路
广开言路 2021-01-17 06:38

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..

Here\'s the snippet of code:

2条回答
  •  借酒劲吻你
    2021-01-17 07:06

    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
    

提交回复
热议问题