Visual Basic Code of the Week (COTW)
Issue #119
Online Version at (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.

Issue topic: Validating credit card numbers

This issue's sponsor -

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!


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


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:

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.

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:

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

Other links

Contact Information

C&D Programming Corp.
PO Box 20128
Floral Park, NY 11002-0128
Phone or Fax: (212) 504-7945