Javascript checks functions in Date Format [relatively full] _ time and date
Source: Internet
Author: User
Very comprehensive, with many functions for date check functions // For date text box name = "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 ();
}
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.