Hi!

Well the Class that I had sent earlier was really
complicated. SO I just found an easier script. Can
anybody tell me how this should work. If it returns 1,
0, -1 what should I do?. I am a begineer so please
bear with me.

THank You


<?php

function  validateCC($ccnum, $type){  


        //Clean  up  input  

        $type  =  strtolower($type);  
        $ccnum  =  ereg_replace( '[-[:space:]]', 
'',$ccnum);   


        //Do  type  specific  checks  

        if  ($type  ==  'unknown')  {  

                //Skip  type  specific  checks  

        }  
        elseif  ($type  ==  'mastercard'){  
                if  (strlen($ccnum)  !=  16  || 
!ereg( '^5[1-5]',  $ccnum))   
return  0;  
        }  
        elseif  ($type  ==  'visa'){  
                if  ((strlen($ccnum)  !=  13  && 
strlen($ccnum)  !=  16)  ||   
substr($ccnum,  0,  1)  !=  '4')  return  0;  
        }  
        elseif  ($type  ==  'amex'){  
                if  (strlen($ccnum)  !=  15  || 
!ereg( '^3[47]',  $ccnum))   
return  a;  
        }  
        elseif  ($type  ==  'discover'){  
                if  (strlen($ccnum)  !=  16  || 
substr($ccnum,  0,  4)  !=   
'6011')  return  0;  
        }  
        else  {  
                //invalid  type  entered  
                return  -1;  
        }  
                

        //  Start  MOD  10  checks  

        $dig  =  toCharArray($ccnum);  
        $numdig  =  sizeof  ($dig);  
        $j  =  0;  
        for  ($i=($numdig-2);  $i>=0;  $i-=2){  
                $dbl[$j]  =  $dig[$i]  *  2;  
                $j++;  
        }         
        $dblsz  =  sizeof($dbl);  
        $validate  =0;  
        for  ($i=0;$i<$dblsz;$i++){  
                $add  =  toCharArray($dbl[$i]);  
                for  ($j=0;$j<sizeof($add);$j++){  
                        $validate  +=  $add[$j];  
                }  
        $add  =  '';  
        }  
        for  ($i=($numdig-1);  $i>=0;  $i-=2){  
                $validate  +=  $dig[$i];   
        }  
        if  (substr($validate,  -1,  1)  ==  '0') 
return  1;  
        else  return  0;  
}  



?>

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to