# How To Validate Credit Card Numbers

Beginners

## Introduction

This is the article which tells you how to validate “Credit Card Number”. This articles doesn’t guarantee that the Credit Card Number exist what it tells that it is the valid number or not.

## Information

Credit Card numbers are (most times) 13 to 16 digit numbers which are protected by a special numerical check, called Luhn check.

## In the two examples above, if a check digit was to be added to the front of these numbers, then 4 might be added to 1111 to make 41111, while 0 would be added to 8763 to make 08763. It is usually the case that check digits are added to the end, although this requires a simple modification to the algorithm to determine an ending check digit given the rest of the account number.

Algorithm

The algorithm proceeds in three steps. Firstly, every second digit, beginning with the next-to-rightmost and proceeding to the left, is doubled. If that result is greater than nine, its digits are summed (which is equivalent, for any number in the range 10 though 18, of subtracting 9 from it). Thus, a 2 becomes 4 and a 7 becomes 5. Secondly, all the digits are summed. Finally, the result is divided by 10. If the remainder is zero, the original number is valid.

## The following is wikicode, a proposed pseudocode for use in many articles.

Source: www.codeproject.com

Category: Credit