snippet library logo
Amazon.com
in category
Javascript / Time / Date / Date Validation
Snippet details
ID: 18
Viewed: 1476
Added: 2001-11-23
Version:
Sorry no demo

User Rated at:
Rate This:
Snippets in this catagory         
Show Printable Version
makes sure some one typed in a valid date in the field

General Details
Snippet uploaded by: snippet
Email : webmaster@snippetlibrary.com
Snippet By: Unknown

<!---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 Reviews to show


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


Subject:

Reviewed By:

Write a review:





Terms of Conditions
Powered By
Avian Hosting
© 2005 snippetlibrary.com All Rights Reserved.