Login   Register  
PHP Classes
elePHPant
Icontem

File: FormVerifications.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Bulent Tezcan  >  AdvancedForm  >  FormVerifications.php  >  Download  
File: FormVerifications.php
Role: Auxiliary script
Content type: text/plain
Description: some useful methods to verify forms
Class: AdvancedForm
Generate forms inside a table, which supports CSS.
Author: By
Last change:
Date: 2002-06-12 07:16
Size: 2,877 bytes
 

Contents

Class file image Download
<?php

    
function DateVerify($date,$format)
    {
        if (!
$date or !$format)
            return 
FALSE;
    
        
$format strtoupper($format);

        Switch (
TRUE)
        {
            case 
$format == "DMY":
            case 
$format == "DDMMYY":
                
$day        substr($date,0,2);
                
$month    substr($date,2,2);
                
$year        substr($date,4,2);
                break;
            case 
$format == "D/M/Y":
            case 
$format == "D:M:Y":
            case 
$format == "D-M-Y":
            case 
$format == "D_M_Y":
            case 
$format == "D M Y":
            case 
$format == "D.M.Y":
                
$day        substr($date,0,2);
                
$month    substr($date,3,2);
                
$year        substr($date,6,2);
                break;

            case 
$format == "MDY":
            case 
$format == "MMDDYY":
                
$month    substr($date,0,2);
                
$day        substr($date,2,2);
                
$year        substr($date,4,2);
                break;
            case 
$format == "M/D/Y":
            case 
$format == "M:D:Y":
            case 
$format == "M-D-Y":
            case 
$format == "M_D_Y":
            case 
$format == "M D Y":
            case 
$format == "M.D.Y":
                
$month    substr($date,0,2);
                
$day        substr($date,3,2);
                
$year        substr($date,6,2);
                break;

            case 
$format == "DDMMYYYY":
                
$day        substr($date,0,2);
                
$month    substr($date,2,2);
                
$year        substr($date,4,4);
                break;
            case 
$format == "DD/MM/YYYY":
            case 
$format == "DD:MM:YYYY":
            case 
$format == "DD-MM-YYYY":
            case 
$format == "DD_MM_YYYY":
            case 
$format == "DD MM YYYY":
            case 
$format == "DD.MM.YYYY":
                
$day        substr($date,0,2);
                
$month    substr($date,3,2);
                
$year        substr($date,6,4);
                break;

            case 
$format == "MMDDYYYY":
                
$month    substr($date,0,2);
                
$day        substr($date,2,2);
                
$year        substr($date,4,4);
                break;
            case 
$format == "MM/DD/YYYY":
            case 
$format == "MM:DD:YYYY":
            case 
$format == "MM-DD-YYYY":
            case 
$format == "MM_DD_YYYY":
            case 
$format == "MM DD YYYY":
            case 
$format == "MM.DD.YYYY":
                
$month    substr($date,0,2);
                
$day        substr($date,3,2);
                
$year        substr($date,6,4);
                break;
        }
        if ( 
IsMonthOk($month) and IsDayOk($day,$month,$year) )
            return 
TRUE;
        else
            return 
FALSE;
    }

    function 
IsDayOk($day,$month,$year)
    {
        if (
$month == || $month == || $month == || $month == 7
                     
|| $month == || $month == 10 || $month == 12)
        {
            if (
$day >= && $day <= 31
                
$result 1;
             else 
                 
$result 0;
        }
        else if (
$month == 2)
        {
            if (
$day >= && $day <=28
                
$result 1;
            else if (
$day == 29 && ($year 4) == 0
                
$result 1;  // valid leap-year
            
else if ($day == 29 && ($year 4) != 0
                
$result 0;
            else 
                
$result 0;
        }
        else
        {
            if (
$day >= && $day <= 30
                
$result 1;
            else 
                
$result 0;
        }
        return 
$result;
    }

    function 
IsMonthOk($month)
    {
         if(
$month <= 12 && $month != 0
            
$result 1;
         else 
             
$result 0;
         
         return 
$result;
    }


?>