//判断input是否符是日期
function isDateString(sDate)
{
var mp=/\d{4}-\d{2}-\d{2}/;
var matchArray = sDate.match(mp);
if (matchArray==null) return false;
var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31];
var iaDate = new Array(3);
var year, month, day;
iaDate = sDate.split("-");
year = parseFloat(iaDate[0])
month = parseFloat(iaDate[1])
day=parseFloat(iaDate[2])
if (year < 1900 || year > 2100) return false;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
if (month < 1 || month > 12) return false;
if (day < 1 || day > iaMonthDays[month - 1]) return false;
return true;
}
使用
if(!isDateString(complete_date))
{
alert("实际完成日期格式不正确,日期格式为yyyy-mm-dd");
return;
}