JavaScript Validation Date function _jquery

Source: Internet
Author: User
Causes the database to run the task to have the error (the task calculates the state according to the date, because the data quantity is bigger, all makes the task to run at night), in order to avoid this kind of mistake again, therefore added a verification date validity the JavaScript method.
This method can effectively validate leap years, supported date formats are: 2009-01-01, 2009/01/01 two formats.
JavaScript code
Copy Code code as follows:

Determine 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 ("Date is wrong!") ");
DateValue = "";
This.focus ();
Return
}
}

Use test
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script type= "Text/javascript" src= "Jquery/jscript1.js" ></script>
<script type= "Text/javascript" src= "Jquery/jquery-vsdoc.js" ></script>
<body>
<input type= "text" id= "Sdate"/>
<script type= "Text/javascript" >
$ ("#sDate"). blur (function () {IsDate ($ (this) [0]);})
</script>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.