Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Credit Card Validation Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
15-Sep-02
Category
Algorithm
Language
Delphi All Versions
Views
89
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: William Gerbert

Credit Card Validation

Answer:

Are you in need to validate a credit card? The following routine does some basic 
checking and returns the type of the credit card as a number - or use the const 
array to get the type of credit card by name. (E.g. 'Mastercard').

This code does not check that the credit card is actually valid, that it is good 
for a purchase or whether it belongs to a certain person. To accept any kind of 
orders, you need to do an address verification, combined with checking the 
expiration date.

The routine is still handy as an input validator on forms. You may download it here.


1   program CardTest;
2   
3   uses
4     Dialogs,
5     SysUtils;
6   
7   {$R *.RES}
8   
9   const
10    CardType: array[0..4] of string = ('Invalid', 'Amex', 'Visa', 'Mastercard',
11      'Discover');
12  
13  function Vc(C: string): Integer;
14  var
15    Card: string[21];
16    VCard: array[0..21] of Byte absolute Card;
17    XCard: Integer;
18    Cstr: string[21];
19    y,
20      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;
61  
62  begin
63    ShowMessage(CardType[Vc('4479750100222862')]);
64  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC