The following content mainly through the JS code to introduce you, the code is relatively simple, including comments, there are good suggestions welcome.
The following figure, when a query condition contains a date, such as "2012-3-4", verifies that the date string entered before the query is a valid date
var snapshot_createtime_begin=$ (selector+ "input[name= ' Createtime_begin ')"). Val (). Trim ();
var snapshot_createtime_end=$ (selector + "Input[name= ' Createtime_end ')"). Val (). Trim (); try{//Determines whether the start time is a valid date if (snapshot_createtime_begin!= "" &&new date (snapshot_createtime_begin). Getdat
E ()!=snapshot_createtime_begin.match (/-\d{0,2}$/g) [0].replace (/-/g, "")) {throw new Error (); //Determine if the end time is a valid date if (snapshot_createtime_end!= "" &&new date (snapshot_createtime_end). GetDate ()!=sn
Apshot_createtime_end.match (/-\d{0,2}$/g) [0].replace (/-/g, "")) {throw new Error (); } if (Date.parse (snapshot_createtime_begin) >date.parse (snapshot_createtime_end)) {//alert ("Start date should not exceed end Date!
"); Alert ("The start date should not exceed the end date!")
");
return; } $.extend (pageobj,{createtimebegin:snapshot_createtime_begin, Createtimeend:snapshot_createt
Ime_end,}); InitpaginatioN (); }catch (e) {//alert ("Please enter a valid date!") Alert ("Please enter a valid date!")
"); }
JS to determine whether the date is a valid day
function IsDate (intyear,intmonth,intday) {
if isNaN (intyear) | | isNaN (intmonth) | | isNaN (Intday)) return false;
if (intmonth>12| | INTMONTH<1) return false;
if (intday<1| | INTDAY>31) return false;
if (intmonth==4| | intmonth==6| | intmonth==9| | intmonth==11) && (intday>30)) return false;
if (intmonth==2) {
if (intday>29) return false;
if (((intyear%100==0) && (intyear%400!=0)) | | (intyear%4!=0)) && (intday>28)) return false;
}
return true;
}
The above code is the validity of the date check, I hope to help you.