whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

32 Visitors Online


 
...validate credit cards?
Autor: Mileriam
Homepage: http://www.mediaceta.de
[ Print tip ]  

Tip Rating (11):  
     


{-------------------------------------------------
  Returns: 

   0  : Card is invalid or unknown
   1  : Card is a valid AmEx
   2  : Card is a valid Visa
   3  : Card is a valid MasterCard

  Ergebnis: 

   0  : Unbekannte Karte
   1  : AmEx Karte
   2  : Visa Karte
   3  : MasterCard Karte
-------------------------------------------------} 

function CheckCC(c: string): Integer;
var 
  
card: string[21]; 
  Vcard: array[0..21] of Byte absolute card; 
  Xcard: Integer; 
  Cstr: string[21];
  y, x: Integer; 
begin 
  
Cstr := ''; 
  FillChar(Vcard, 22, #0);
  card := c; 
  for x := 1 to 20 do 
    if 
(Vcard[x] in [48..57]) then 
      
Cstr := Cstr + chr(Vcard[x]); 
  card := '';
  card := Cstr;
  Xcard := 0; 
  if not odd(Length(card)) then 
    for 
x := (Length(card) - 1) downto do 
    begin 
      if 
odd(x) then
        
y := ((Vcard[x] - 48) * 2)
      else 
        
y := (Vcard[x] - 48); 
      if (y >= 10) then 
        
y := ((y - 10) + 1); 
      Xcard := (Xcard + y) 
    end 
  else
    for 
x := (Length(card) - 1) downto do
    begin
      if 
odd(x) then 
        
y := (Vcard[x] - 48) 
      else 
        
y := ((Vcard[x] - 48) * 2); 
      if (y >= 10) then 
        
y := ((y - 10) + 1);
      Xcard := (Xcard + y) 
    end
  x := (10 - (Xcard mod 10)); 
  if (x = 10) then
    
x := 0; 
  if (x = (Vcard[Length(card)] - 48)) then
    
Result := Ord(Cstr[1]) - Ord('2')
  else 
    
Result := 0
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  case 
CheckCC(Edit1.Text) of
    
0: Label1.Caption := 'Card is invalid or unknown';
    1: Label1.Caption := 'Card is a valid AmEx';
    2: Label1.Caption := 'Card is a valid Visa';
    3: Label1.Caption := 'Card is a valid MasterCard';
  end;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners