JavaScript check date format function [Compare full]_ time Date

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 ("Please 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 empty");
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% = 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 ();
}
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.