第一种方法比较简单,将输入的日期替换分隔后进行判断。 function isDate(value) { try { value = value.replace("-", "/").replace(".", "/"); var SplitValue = value.split("/"); var OK = true; if (!(SplitValue[0].length == 1 || SplitValue[0].length == 2)) { OK = false; } if (OK && !(SplitValue[1].length == 1 || SplitValue[1].length == 2)) { OK = false; } if (OK && SplitValue[2].length != 4) { OK = false; } if (OK) { var Day = parseInt(SplitValue[0]); var Month = parseInt(SplitValue[1]); var Year = parseInt(SplitValue[2]); if (OK = ((Year > 1900) && (Year < new Date().getFullYear()))) { if (OK = (Month <= 12 && Month > 0)) { var LeapYear = (((Year % 4) == 0) && ((Year % 100) != 0) || ((Year % 400) == 0)); if (Month == 2) { OK = LeapYear ? Day <= 29 : Day <= 28; } else { if ((Month == 4) || (Month == 6) || (Month == 9) || (Month == 11)) { OK = (Day > 0 && Day <= 30); } else { OK = (Day > 0 && Day <= 31); } } } } } return OK; } catch (e) { return false; } } 第二种采用正则表达式进行匹配。 function isDate(value) { var dateRegEx = new RegExp(/^(?:(?:(?:0?[13578]|1[02])(//|-)31)|(?:(?:0?[1,3-9]|1[0-2])(//|-)(?:29|30)))(//|-)(?:[1-9]/d/d/d|/d[1-9]/d/d|/d/d[1-9]/d|/d/d/d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(//|-)(?:0?[1-9]|1/d|2[0-8]))(//|-)(?:[1-9]/d/d/d|/d[1-9]/d/d|/d/d[1-9]/d|/d/d/d[1-9])$|^(0?2(//|-)29)(//|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:/d/d)?(?:0[48]|[2468][048]|[13579][26]))$/); if (dateRegEx.test(value)) { return true; } return false; }