Javascript checks functions in Date Format [relatively complete]

Source: Internet
Author: User

// Text box name for date = "indate"
Function check1 (form)
{
For (I = 0; I <form. length; I ++)
{
If (Form. elements [I]. value = "")
{
Alert ("complete! ")
Form. elements [I]. Focus ();
Return;
}

If (Form. elements [I]. Name = "indate ")
{
VaR date = form. elements [I]. value;
Len = date. length;
VaR datearray = date. Split ("-")
// Alert (datearray [1]);
VaR year = parseint (datearray [0]);
VaR month = parseint (datearray [1]);
VaR day = parseint (datearray [2]);

If (LEN = "")
{
Alert ("time cannot be blank ");
Return;
}
Else if (LEN> 10)
{
Alert ("incorrect date format ");
Return;
}
Else if (isnan (year ))
{
Alert ("incorrect date format ");
Return;
}
Else if (Year> 9999) | (year <100 ))
{
Alert ("incorrect date format ");
Return;
}
Else if (isnan (month ))
{
Alert ("incorrect date format ");
Return;
}
Else if (month> 12) | (month <1 ))
{
Alert ("incorrect date format ");
Return;
}
Else if (isnan (day ))
{
Alert ("incorrect date format ");
Return;
}
Else
{
Switch (month)
{
Case 1:
Case 3:
Case 5:
Case 7:
Case 8:
Case 10:
Case 12:
If (DAT <0) | (day> 31 ))
{
Alert ("incorrect date format ");
Return;
}
Break;
Case 4:
Case 6:
Case 9:
Case 11:
If (day <0) | (day> 30 ))
{
Alert ("incorrect date format ");
Return;
}
Break;
Default:
If (Year % 100 = 0) & (Year % 4 = 0 ))
{
If (day <0) | (day> 29 ))
{
Alert ("incorrect date format ");
Return;
}
}
Else
{
If (day <0) | (day> 28 ))
{
Alert ("incorrect date format ");
Return;
}
}
}
}
}
}
Form. Submit ();
}

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.