This article describes how to verify the date format of JavaScript. If you need it, refer to it.
The Code is as follows:
Function checkInputDate (obj ){
Var strDate = obj. value;
Var re =/^ (\ d {4})-(\ d {2})-(\ d {2}) $ /;
If (re. test (strDate) // determines that the date format complies with the 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) // judge the date Logic
{
Document. getElementById ("errorMessage"). innerText = "You can only input Date. (YYYY-MM-DD )! ";
Document. getElementById ("error"). style. display = "";
Obj. value = '';
}
} Else {
Document. getElementById ("errorMessage"). innerText = "You can only input Date. (YYYY-MM-DD )! ";
Document. getElementById ("error"). style. display = "";
Obj. value = '';
}
}