This article provides a date validation function is tested, the following many places using alert to prompt, because it is a test so give a hint, of course, if you want to change the alert to return to become, the following have marked.
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> a date validation function </title>
<script>
function IsDate ()
{
var datestr = document.getElementById (' dates '). Value;
var Datepat =/^ (D{4}) (-) (d{1,2}) (-) (d{1,2}) $/;
var Matcharray = Datestr.match (Datepat);
if (Matcharray = null) alert (' Please enter Date ');//return false;
var month = matcharray[3];
var day = matcharray[5];
var year = matcharray[1];
if (Month < 1 | | | month >) alert (' Incorrect month '); You can change it to return false.
if (Day < 1 | | | |) alert (' incorrect date '); You can change it to return false.
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;
}
Alert (' right date '); You can change it to return true
}
</script>
<body>
<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<label for= "TextField" ></label>
Enter Date (2010-11-03)
<input type= "text" name= "dates" id= "dates"/>
<input type= "button" name= "button" id= "button" value= "Test" onclick= "Web Effects: Return IsDate ();"/>
</form>
</body>