Author: Giannis Sampaziotis A routine to validate and identify Visa/MasterCard/Amex credit cards. Might come handy if you want to perform arbitrary card checking. Original code by Daniel J. Karnes (1990) Answer: 1 2 {------------------------------------------------- 3 Credit card validator 4 5 Returns: 6 7 0 : Card is invalid or unknown 8 1 : Card is a valid AmEx 9 2 : Card is a valid Visa 10 3 : Card is a valid MasterCard 11 12 -------------------------------------------------} 13 14 function Vc(c: string): integer; 15 var 16 card: string[21]; 17 Vcard: array[0..21] of byte absolute card; 18 Xcard: integer; 19 Cstr: string[21]; 20 y, x: integer; 21 begin 22 Cstr := ''; 23 fillchar(Vcard, 22, #0); 24 card := c; 25 for x := 1 to 20 do 26 if (Vcard[x] in [48..57]) then 27 Cstr := Cstr + chr(Vcard[x]); 28 card := ''; 29 card := Cstr; 30 Xcard := 0; 31 if not odd(length(card)) then 32 for x := (length(card) - 1) downto 1 do 33 begin 34 if odd(x) then 35 y := ((Vcard[x] - 48) * 2) 36 else 37 y := (Vcard[x] - 48); 38 if (y >= 10) then 39 y := ((y - 10) + 1); 40 Xcard := (Xcard + y) 41 end 42 else 43 for x := (length(card) - 1) downto 1 do 44 begin 45 if odd(x) then 46 y := (Vcard[x] - 48) 47 else 48 y := ((Vcard[x] - 48) * 2); 49 if (y >= 10) then 50 y := ((y - 10) + 1); 51 Xcard := (Xcard + y) 52 end; 53 x := (10 - (Xcard mod 10)); 54 if (x = 10) then 55 x := 0; 56 if (x = (Vcard[length(card)] - 48)) then 57 Vc := ord(Cstr[1]) - ord('2') 58 else 59 Vc := 0 60 end;