This leads to errors in database running tasks (tasks calculate status based on dates, and due to the large amount of data, tasks are run at night). In order to avoid such errors from happening again, a JavaScript method to verify the validity of the date is added.
This method can effectively verify leap years. The supported date formats are: 2009-01-01 and 2009/01/01.
javascript code
//Judge whether the date is legal
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\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("Wrong date!");
dateValue = "";
this.focus();
return;
}
}
Use test