js验证日期是否正确
/** * 验证日期是否正确 * 日期格式: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; } 来源: https://www.cnblogs.com