Credit card number verification algorithm __ algorithm

Source: Internet
Author: User
Tags valid
How to check digits on credit card validation

Article Source: http://platon.sk/article.php?38

Author:hal Stiles | Section:dev Resources | date:2005-06-25

This document outlines procedures and algorithms for verifying, accuracy and validity of credit card numbers. Most credit card numbers is encoded with a "Check Digit". A check digit is a digit added to a number (either at the end or the beginning) that validates the authenticity of the NUM ber.

A simple algorithm are applied to the other digits of the number which yields the check digit. By running the algorithm, and comparing the check digit you get from the algorithm with the check digit encoded with the C Redit card number, you can verify so you had correctly read all of the digits and that they make a valid combination.

Possible uses for this information:when a user have keyed in a credits card number (or scanned it) and you want to validate It before sending it for debit authorization. When issuing cards, say an affinity card, you might want to add a check digit using the MOD method. Prefix, Length, and Check Digit Criteria

Here is a table outlining the major credits cards that's might want to validate.

card type Prefix Length Check digit algorithm
MASTERCARD 51-55 + mod ten
VISA 4 13, 16 mod
AMEX the PNs 15 mod
diners club/carte blanche 300-305 mod
Discover 6011 + mod 10
enRoute 2149 all any
JCB 3 + mod ten
JCB 2131 1800 mod
LUHN Formula (Mod) for Validation of Primary account number

The following steps is required to validate the primary account number:

Step 1: Double the value of alternate digits of the primary account number beginning and the second digit from the right (the FIR St Right--hand Digit is the check digit.)

Step 2: ADD the individual digits comprising the products obtained in Step 1 to all of the unaffected digits in the original numb Er.

Step 3: The total obtained in Step 2 must is a number ending in zero (+,, etc) for the account number to be validated.

For example, to validate the primary account number 49927398716:

Step 1:

        4 9 9 2 7 3 9 8 7 1 6
X2 x2 x2 x2
------------------------------
4 6 2

Step 2:

4 + (1+8) + 9 + (4) + 7 + (6) + 9 + (1+6) + 7 + (2) + 6

Step 3: Sum = + = Card number is validated

Note:card is valid because the 70/10 yields no remainder. Resources

The great folks at ICVerify is the original source of this data, I only formatted it in HTML.

If you is in the market, I wrote a set of FoxPro modules for Windows/dos that interface nicely with icverify in a multi-u Ser LAN setup. You just set up icverify to a single station, and all stations on the LAN can authorize credits cards with a single FOXBASE Function call. Of course, you had to license icverify by the node, but it was very reasonable. I also wrote a couple of simple functions to perform pre-authorization, card screening, etc.

Here's a Microsoft Excel worksheet that would validate a number for you.

Horace Vallas made a neowebscript (Tcl really) procedure that implements it. Check it out at http://nws.sourceforge.net/

Because I get at least a letter a week regarding this routine, here is some additional helpful notes:

Make sure this you:have started with the rightmost digit (including the check digit) (figure odd and even based upon the Rightmost digit being odd, regardless of the length of the credit Card.) Always-work-right-to-left. The check digit counts as digit #1 (assuming, the rightmost digit is the check digit) and are not doubled. Double every second digit (starting with digit # 2 from the right). Remember that if you double a number over 4, (6 for example) you don't add the result to your total, but rather the sum of the digits of the result (in the above example 6*2=12 so you would add 1+2 to your total (not 12). Always include the Visa or m/c/prefix. Article was originally released on the Hal Stiles webpage server and in the Platon.sk content management system it is publ Ished with author and host Administrator agreeement.

Common credit card number rules

Issuer Identifier Card Number Length
Diner ' s Club 300xxx-305xxx, 3095xx,36xxxx, 38xxxx 14
American Express 34xxxx, 37xxxx 15
VISA 4xxxxx 13, 16
MasterCard 51xxxx-55xxxx 16
JCB 3528xx-358xxx 16
Discover 6011xx 16
UnionPay 622126-622925 16
Credit card number verification basic algorithm:
1, even digit card number odd digits on the number, odd digit card number even digits on the number.
2, the number of digits greater than 10 minus 9.
3. Add up all the figures.
4, the result is not a multiple of 10 of the card number is illegal.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.