Version: 0.0.1

Type: Function

Category: Calendars/Dates

License: GNU General Public License

Description: a date validation that accepts YYYY-MM-DD,YYYY/MM/DD,MM-DD-YYYY and MM/DD/YYYY format



<?php 

      /*#################################################
      ##                RockSHOX - PHIL.               ##
      ##                allan albacete                 ##
      ## Date validation in format of (YYYY-MM-DD) or  ##
      ##                  (YYYY/MM/DD) or              ##
      ##           (MM-DD-YYYY) or (MM/DD/YYYY)        ##
      ##              hope it helps  may 5, 2004       ##
      ##################################################*/
      $date = "08-12-2004";
      validate_date($date);
      function validate_date($date)
      { 
      if ((ereg ("([0-9]{4})-([0-9]{2})-([0-9]{2})", $date, $regs)) or 
                (ereg ("([0-9]{4})/([0-9]{2})/([0-9]{2})", $date, $regs))){
        
        list($wholeyear, $year,$month,$day) = $regs;   
        
      }                    
      elseif((ereg ("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})", $date, $regs)) or
                   (ereg ("([0-9]{2})/([0-9]{2})/([0-9]{4})", $date, $regs))){
         
         list($wholeyear,$month,$day,$year) = $regs;   
      }                                                                   
      else  
      {
           print 'invalid date';
           return false;
      }
      
      if ($day > 31){
           print 'Invalid Day';
           return false;
      }
      elseif ($month > 12){
           print 'Invalid Month';
           return false;
      }
      print $regs[0];
      return validate_date;
      }         
   
?>