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
Yet Another Credit Card Validator 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
11-Jun-03
Category
Algorithm
Language
Delphi 3.x
Views
150
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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;


			
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