JavaScript determines whether the date function code

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax code content date function html http it is

JavaScript Tutorial To determine if it is a date function code
<html xmlns= "http://www.jzread.com/1999/xhtml"
<head>
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/>
<title>javascript judge whether it is a date function code </title>

<script language= "javascript"
function isDate (datestr) {
    var datepat =/^ (D{4}) (-) (d{1,2}) (-) (d{1,2}) $/;
    var matcharray = Datestr.match (Datepat);
    if (Matcharray = null) return false;
    var month = matcharray[3];
    var day = matcharray[5];
    var year = matcharray[1];
    if (Month < 1 | | month >) return false;
    if (Day < 1 | |
    if ((month==4 | | month==6 | | | month==9 | | month==11) && day==31) return false;
    if (month = 2) {
        var isleap = (Year% 4 = 0 & & (Year%!= 0 | |-year% 400 = 0));
        if (Day > 29 | | (day==29 &&!isleap)) return false;
   }
    return TRUE;

</script>
</head>

<body>
</body>
</html>
 

Related Article

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.