Mega Code Archive

 
Categories / Delphi / Examples
 

Validate a Credit Card

Title: Validate a Credit Card Question: Validate a Credit Card? Answer: //You need just a Button and an Edit Box procedure TForm1.Button1Click(Sender: TObject); var i,digit,sum:integer; begin sum:=0; for i:=16 downto 1 do begin digit:=strtoint(edit1.Text[i]); if digit mod 2=0 then sum:=sum+digit else sum:=sum+(digit*2); end; if sum mod 10=0 then messagebox(0,'Credit card is valid','info',0) else messagebox(0,'Credit card is NOT valid','info',0); end; {Next time, I will write complicated example..How to validate credit card by prefixes etc.} // // Have a fun //