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.

Find out with our salary calculator at

http://www.cybercoders.com/developer/salary_calc/default.asp?ad=cotw

and make sure you're getting paid what you are worth!

- Visual Basic 3.0 or higher.

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

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).

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.

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)

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

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

- Advertising - http://www.codeoftheweek.com/links/ad.html
- Back Issues - http://www.codeoftheweek.com/issues/index.html
- Feedback - http://www.codeoftheweek.com/feedback.html
- Submissions - http://www.codeoftheweek.com/submission.html
- Suggestions - http://www.codeoftheweek.com/feedback.html
- Subscriptions - http://www.codeoftheweek.com/order.html
- Comments - http://www.codeoftheweek.com/feedback.html
- Cancellations - cancel@codeoftheweek.com

PO Box 20128

Floral Park, NY 11002-0128

Phone or Fax: (212) 504-7945

Email: info@codeoftheweek.com

Web: http://www.codeoftheweek.com