[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Creating unique credit card-like numbers

Posted on 2004-04-20
2
Medium Priority
?
188 Views
Last Modified: 2010-04-05
I need to CREATE a number like a credit card number that will also use the same MOD10 Checksum algorithm
that a credit card uses. I have the validation routines but can't figure out how to CREATE the numbers.

Any ideas or links?
0
Comment
Question by:Eddie Shipman
2 Comments
 
LVL 26

Author Comment

by:Eddie Shipman
ID: 10872464
No, I am not generating fake credit card numbers. This is for product registration and, no, I do not want to use GUIDs.
0
 
LVL 17

Accepted Solution

by:
mokule earned 500 total points
ID: 10873513
You must generate 15 digit number and this function will generate the 16-th rightmost digit.

function TForm1.Generate(str: string): string;
var
  i: integer;
  len: integer;
  su: integer;
  dig: integer;
begin
  len := Length(str);
  su := 0;
  for i := 0 to len-1 do
    begin
    dig := Ord(str[len-i]) - Ord('0');
    if (i mod 2) = 1 then
      su := su + dig
    else if dig < 5 then
      su := su + 2 * dig
    else
      su := su + 1 + 2 * dig - 10;
    end;
  if su mod 10 = 0 then
    Result := str + '0'
  else
    Result := str + Char(Ord('0') + 10 - su mod 10);
end;
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question