【编者按】网学网正则表达式频道为大家收集整理了“js:日期正则表达式及检测“提供大家参考,希望对大家有所帮助!
这是yyyy-mm-dd hh:mm:ss 的
/^(\d{4})\-(\d{2})\-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/ ;
这是 yyyy-mm-ddde 的
/^(\d{4})\-(\d{2})\-(\d{2})$/
function validateCNDate( strValue ) {
var objRegExp = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
if(!objRegExp.test(strValue))
return false;
else{
var arrayDate = strValue.split(RegExp.$1);
var intDay = parseInt(arrayDate,10);
var intYear = parseInt(arrayDate[0],10);
var intMonth = parseInt(arrayDate,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[parseInt(arrayDate)] != null) {
if(intDay <= arrayLookup[parseInt(arrayDate)] && intDay != 0)
return true;
}
if (intMonth-2 ==0) {
var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
return true;
}
}
return false;
}