验证日期的Javascript
验证输入的日期是否是dd/MM/yyyy格式,并且最后判断是否大于等于当前日期。
function ValidateDate(strValue)
{
var objRegExp = /^(\d{2})\/(\d{2})\/(\d{4})$/;
if(!objRegExp.test(strValue))
return false;
else
{
var arrayDate = strValue.split('/');
var intDay = parseInt(arrayDate[0],10);
var intYear = parseInt(arrayDate[2],10);
var intMonth = parseInt(arrayDate[1],10);
if(intMonth > 12 || intMonth < 1) return false;
var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31, '8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31};
if(arrayLookup[intMonth] != null)
{
if(intDay > arrayLookup[intMonth] || intDay == 0)
return false;
}
if (intMonth==2)
{
var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
if( ((booLeapYear && intDay > 29) || (!booLeapYear && intDay >28)) || intDay ==0)
return false;
}
var currentDate = new Date();
var cYear = currentDate.getFullYear();
var cMonth = currentDate.getMonth()+1;
var cDay = currentDate.getDate();
if(cYear*10000+cMonth*100+cDay > intYear*10000+intMonth*100+intDay)
return false;
}
return true;
}
{
var objRegExp = /^(\d{2})\/(\d{2})\/(\d{4})$/;
if(!objRegExp.test(strValue))
return false;
else
{
var arrayDate = strValue.split('/');
var intDay = parseInt(arrayDate[0],10);
var intYear = parseInt(arrayDate[2],10);
var intMonth = parseInt(arrayDate[1],10);
if(intMonth > 12 || intMonth < 1) return false;
var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31, '8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31};
if(arrayLookup[intMonth] != null)
{
if(intDay > arrayLookup[intMonth] || intDay == 0)
return false;
}
if (intMonth==2)
{
var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
if( ((booLeapYear && intDay > 29) || (!booLeapYear && intDay >28)) || intDay ==0)
return false;
}
var currentDate = new Date();
var cYear = currentDate.getFullYear();
var cMonth = currentDate.getMonth()+1;
var cDay = currentDate.getDate();
if(cYear*10000+cMonth*100+cDay > intYear*10000+intMonth*100+intDay)
return false;
}
return true;
}