

ID: 18
Viewed: 3630
Added: Nov 23, 2001
Version:



Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo



Thank you for your vote. Please wait...
It appears you already voted for this snippet
It appears your vote value was empty


makes sure some one typed in a valid date in the field
<!---Head--->
<SCRIPT LANGUAGE="JavaScript">
function y2k(number) {
return (number < 1000) ? number + 1900 : number;
}
var reason = '';
function isValidDate (myDate,sep) {
// checks if date passed is in valid dd/mm/yyyy format
if (myDate.length == 10) {
if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep) {
var date = myDate.substring(0,2);
var Month = myDate.substring(3,5);
var Year = myDate.substring(6,10);
var test = New Date(Year,Month-1,date);
if (Year == y2k(test.getYear()) && (Month-1 == test.getMonth()) && (date == test.getDate())) {
reason = '';
return True;
}
else {
reason = 'valid Format but an invalid date';
return False;
}
}
else {
reason = 'invalid spearators';
return False;
}
}
else {
reason = 'invalid length';
return False;
}
}
function tellMeIfInvalid(myDate) {
if (isValidDate(myDate,'/'))
document.write(myDate + ' = valid date<BR>');
else
document.write(myDate + ' = ' + reason + '<BR>');
}
tellMeIfInvalid('21/02/1999');
tellMeIfInvalid('2190291999');
tellMeIfInvalid('2/02/1999');
tellMeIfInvalid('21/2/1999');
tellMeIfInvalid('21/02/199');
tellMeIfInvalid('32/02/1999');
tellMeIfInvalid('21/02/1999');
//-->
</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.
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.