Not a Member Yet,
Click here to Register
How do you like the new design?






ID: 19
Viewed: 5106
Added: Nov 23, 2001
Version:
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo



User Rated at: 1 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

validates the date

<!---Head--->
<SCRIPT LANGUAGE="JavaScript">
var dt1 = document.all.Item("txtField1");
dy = dt1.value.substr(0,2);
mn = dt1.value.substr(3,2);
yr = dt1.value.substr(6,4);

if (!ValidateDate(dy,mn,yr)){
alert("The date entered must 10 characters long and take the form of 06/04/2000");
dt1.Select();
return;
}

function ValidateDate(dy,mn,yr){

var date = New array(2);
date[0] = dy;
date[1] = mn;
date[2] = yr;
var j = 0;

if (date[0].substr(0,1) == '0')
date[0] = date[0].substr(1,1);


Switch (parseFloat(date[1])) {

Case 1:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 31))
return false;
break;
Case 2:
if ((date[2] % 4.0) == 0){
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 29))
return false;
}else
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 28))
return false;
break;
Case 3:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 31))
return false;
break;
Case 4:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 30))
return false;
break;
Case 5:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 31))
return false;
break;
Case 6:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 30))
return false;
break;
Case 7:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 31))
return false;
break;
Case 8:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 31))
return false;
break;
Case 9:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 30))
return false;
break;
Case 10:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 31))
return false;
break;
Case 11:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 30))
return false;
break;
Case 12:
if ((parseInt(date[0]) < 1) || (parseInt(date[0]) > 31))
return false;
break;
default:
return false;
break;
}

if ((parseInt(date[2]) < 0) || (isNaN(date[2])) || (date[2].length ==0))
return false;
else
return true;

}
</script>

<!---Body--->


 none


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions