/**
* 验证日期是否正确
* 日期格式:yyyy-mm-dd,yyyy-m-d,yyyy/mm/dd,yyyy/m/d
*/
function checkDate(dateStr) {
  dateStr = dateStr.replace(/\//g, '-');
  var dateReg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/;
  var rValue = dateStr.match(dateReg);
  if (rValue == null) {
    return false;
  }
  rValue[1] = parseInt(rValue[1], 10);
  rValue[2] = parseInt(rValue[2] - 1, 10);
  rValue[3] = parseInt(rValue[3], 10);
  var dateObj = new Date(rValue[1], rValue[2], rValue[3]);
  if (dateObj.getFullYear() != rValue[1] || dateObj.getMonth() != rValue[2] || dateObj.getDate() != rValue[3]) {
    return false;
  }
  return true;
}

 

相关文章:

  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案