Home  >  Article  >  Web Front-end  >  javascript date verification function_jquery

javascript date verification function_jquery

WBOY
WBOYOriginal
2016-05-16 18:32:021037browse

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

Copy code The code is as follows:

//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
Copy code The code is as follows:











< ;/body>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn