JS to determine whether the time format is correct code:
If the requirements are more stringent, the time format is also required to judge, the following is a code example, I hope to be able to bring some help to the needs of friends.
The code example is as follows:
functionisdatestring (strdate) {varStrseparator = "-"; varStrdatearray; varintyear; varIntmonth; varIntday; varboolleapyear; varErrorMsg = ""; Strdatearray=Strdate.split (Strseparator); if(Strdatearray.length! = 3) {errormsg+ = "Date format must be: YYYY-MM-DD"; returnerrormsg; } intyear= parseint (strdatearray[0],10); Intmonth= parseint (strdatearray[1],10); Intday= parseint (strdatearray[2],10); if(IsNaN (intyear) | | IsNaN (intmonth) | |IsNaN (Intday)) {errormsg+ = "Date format error: Year date must be a pure number"; returnerrormsg; } if(intmonth>12 | | intmonth<1) {errormsg+ = "Date format error: Month must be between 1 and 12"; returnerrormsg; } if((intmonth==1| | intmonth==3| | intmonth==5| | intmonth==7 | | intmonth==8| |intmonth==10| | intmonth==12) && (intday>31| | Intday<1) ) {errormsg+ = "date format error: Otsuki must be between 1 and 31 days"; returnerrormsg; } if((intmonth==4| | intmonth==6| | intmonth==9| | intmonth==11) && (intday>30| | Intday<1) ) {errormsg+ = "Date format error: The number of days in a Yue must be between 1 and 31"; returnerrormsg; } if(intmonth==2) { if(Intday < 1) {errormsg+ = "Date format error: Date must be greater than or equal to 1"; returnerrormsg; } boolleapyear=false; if((intyear%100) = = 0) { if((intyear%400) = = 0) Boolleapyear=true; } Else { if((intyear% 4) = = 0) Boolleapyear=true; } if(boolleapyear) {if(Intday > 29) {errormsg+ = "date format error: February days of leap year cannot exceed 29"; returnerrormsg; } } Else { if(Intday > 28) {errormsg+ = "date format error: February days for non-leap years cannot exceed 28"; returnerrormsg; } } } returnerrormsg;}
The original address is: http://www.51texiao.cn/javascriptjiaocheng/2015/0523/2309.html
The most original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=9318
JS to determine whether the time format is correct code