Visual Basic Code of the Week (COTW)
http://www.codeoftheweek.com
Issue #119
Online Version at http://www.codeoftheweek.com/membersonly/bi/0119.html (paid subscribers only)
All content and source code is Copyright (c) 2000 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp.

## This issue's sponsor - cybercoders.com

Web Developers get paid big bucks! Do you?
Find out with our salary calculator at
and make sure you're getting paid what you are worth!

## Requirements

• Visual Basic 3.0 or higher.

## In this Issue

In this issue we discuss how use the LUHN credit card number validation formula. This is sometimes called the MOD 10 formula.

If you have any questions about using this module, let us know at questions@codeoftheweek.com

#### basCCValidate

This module contains a single routine called CreditCardValidate that takes a string of digits, removes all characters other than numbers and performs the Luhn validation formula (mod 10 formula).

This algorithm works by doing the following:

• A checksum is calculated by summing all the alternate digits starting with the rightmost digit and moving to the left.
• Once this sum is calculated start with the second to last digit and double each alternate digit (basically you are using each number you did not use in the first step) moving to the left. After doubling each digit add it to the total calculated in the first step.
• If the doubling of a digit results in a number greater or equal to 10 then subtract 9 from the overall total for each digit that is greater or equal to 10. The final sum after processing all the digits should be a multiple of ten if the credit card number is valid.

If you had a number such as 372712312312345 the formula would calculate like this: 5+3+1+2+3+1+2+3 for the first step. The first part of the second step would be (4*2)+(2*2)+(3*2)+(1*2)+(2*2)+(7*2)+(7*2) which would result in the following additions 8+4+6+3+4+(14-9)+(14-9).

#### Functions

```Public Function CreditCardValidate(sCardNumber As String) As Boolean
```

The sCardNumber is the full credit card number to validate. It can have spaces or dashes anyplace in the number.

#### Sample Usage

Some examples are shown using different credit card numbers (NOTE: the credit card numbers are not real card numbers).

```    Debug.Print CreditCardValidate("4234123412341234")
' will print out as True (if the credit card was actually a real card number)
```

## Source Code

To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0119.html

## This document is available on the web

Paid subscribers can view this issue in HTML format. There is no additional source or information in the HTML formatted document. It just looks a little better since we have included some HTML formatting. Just point your browser to link at the top of this document.

## Get paid to surf the web!

If you would like to get paid for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html