This article introduces the JS to date format validation examples, the need for friends can refer to the
copy code code as follows:
function Checkinputdate (obj) {
var Strdate=obj.value;
var re =/^ (D{4})-(D{2})-(d{2}) $/;
if (Re.test (strdate))//Judgment date format conforms to YYYY-MM-DD standard
{
var dateelement=new Date (Regexp.$1,parseint (regexp.$2,10) -1,regexp.$3);
if (!) ( (Dateelement.getfullyear () ==parseint (regexp.$1)) && ((Dateelement.getmonth () +1) ==parseint (regexp.$2,10)) && (Dateelement.getdate () ==parseint (regexp.$3)))//Judgment date logic
{
document.getElementById ("ErrorMessage"). innertext = "can only input Date." (YYYY-MM-DD)! ";
document.getElementById ("Error"). Style.display = "";
Obj.value= ';
}
}else{
document.getElementById ("ErrorMessage"). innertext = "can only input Date." (YYYY-MM-DD)! ";
document.getElementById ("Error"). Style.display = "";
Obj.value= ';
}
}