http://www.qdfuns.com/notes/17398/6ab5134ceb33cc22e9e15d46d53cae9c.html

 

var reg = /\d{4}([\-\.\/])\d{2}\1\d{2}/;
console.log(reg.test('2016-06-07'));//=>true
console.log(reg.test('2016.06.07'));//=>true
console.log(reg.test('2016/06/07'));//=>true
console.log(reg.test('2016-06/07'));//=>false

  

保持一致性  前面匹配了 -  后面必须是 -  ,  这就是\1 这个占位符, 像跟屁虫似的.

相关文章:

  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-07-26
  • 2021-12-08
猜你喜欢
  • 2022-01-22
  • 2021-11-17
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案