There are several areas in this project that need to be entered recently. Since there is no validity verification for these areas at the beginning, there are many invalid dates in the result user input date, such as 2007-2-29, there are also error dates such as-2-30, which cause errors in database running tasks (the task is calculated based on the date, because the data volume is large, and all tasks are run at night). To avoid such errors, therefore, a javascript method is added to verify the validity of the date.
This method can effectively verify the leap year. Supported date formats include 2009-01-01 and 2009/01/01.
Javascript code
The Code is as follows:
// Determine whether the date is valid
Function IsDate (oTextbox ){
Var regex = new RegExp ("^ (? :(? :( [0-9] {4} (-| \/)(? :(? : 0? [1, 3-9] | 1 [0-2]) (-| \/)(? : 29 | 30) | ((? : 0? [13578] | 1 [02]) (-| \/) 31) | ([0-9] {4} (-| \/)(? : 0? [1-9] | 1 [0-2]) (-| \/)(? : 0? [1-9] | 1 \ d | 2 [0-8]) | (((? :( \ D (? : 0 [48] | [2468] [048] | [13579] [26]) | (? : 0 [48] 00 | [2468] [048] 00 | [13579] [26] 00) (-| \/) 0? 2 (-| \/) 29) $ ");
Var dateValue = oTextbox. value;
If (! Regex. test (dateValue )){
Alert ("date error! ");
DateValue = "";
This. focus ();
Return;
}
}
Use test
The Code is as follows: