web marketing

Search site

Web Marketing Resources Home

Web Marketing Articles

Search Engine Optimization

Free Training

Marketing Jokes

Current Issue

Back Issues

John's Articles

Free Search Engine Marketing & Optimization Tools:

Keyword Suggest
Keyword Density
Keyword Typos
PageRank Search
Future PageRank
Link Popularity

Chamber of Commerce - on the Web logo

Validating Credit Card Numbers


by Will Bontrager



If you collect credit cards on your site, the JavaScript presented with this article can save a lot of frustration.

* If you collect and send credit card information
        to a payment gateway:

The JavaScript can spot typographical errors before connecting your customer to the gateway. If your customer types a "7" instead of a "6," for example, the JavaScript will know something is wrong. You can allow your customer to correct the credit card number before getting a "credit card declined" message.

* If you collect and store credit card information on your secure server for later processing:

The JavaScript can spot typographical errors in the credit card number before you try to process it. Correcting the number right then and there can save you the time otherwise spent trying to contact the customer to get the right number.

Note: The JavaScript does not test whether or not the credit card itself is good. It just tests the number.

The JavaScript uses the Mod-10 algorithm to validate credit card numbers. It can also identify credit card types (MC, Visa, and so forth).

The Mod-10 algorithm is a special method of adding up the digits of a credit card number (reverse the order of the digits, multiply every other digit by 2, add together all of the resulting digits) and then dividing the result by 10. If the remainder is zero, the number passes. Otherwise, it fails.

The Mod-10 process is described in the article, "Creating a Credit Card Validation Class With PHP" by Mitchell Harper, available as of this writing at http://www.webmasterbase.com/article/728

The JavaScript has customization instructions. It's only four steps:

     1. What message to display if the credit card number
        doesn't pass the Mod-10 algorithm.

     2. What message to display if the credit card type is

     3. What message to display if the type is unknown and
        the Mod-10 fails.

     4. Whether or not to display a message when the credit
        card passes the tests.

The JavaScript is free to use from the demo page. Use your browser's "view source" to get the code or download the zip file. The URL is http://willmaster.com/a/14/pl.pl?145d

All of the JavaScript functions go into the HEAD area of your web page.

Give it a try. I think you'll find it useful.

For advanced users, the JavaScript functions provide values for three different variables. You can retrieve and use the values in your own JavaScript or CGI programs. The values are:

     1. The name of the credit card as determined by the
        credit card number provided.

     2. Whether or not the credit card number is of a valid
        format (passed the Mod-10 test).

     3. The credit card number that was checked, minus any
        spaces, hyphens, and other non-numeric characters
        the user might have typed.

More information is presented in the source code, as comments. http://willmaster.com/a/14/pl.pl?145d

Copyright 2002 Bontrager Connection, LLC
"WillMaster Possibilities" ezine  http://willmaster.com/possibilities/
mailto:[email protected]

Make your websites do more than just show text and pretty pictures and tap into the mother lode of free and low-cost Internet CGI applications available on the Net, putting them to work for you and your online enterprise.

The catch? You'll need to know how to install them on your server. William Bontrager shows you how.


©WebMarketingEzine.com 2000-2015
Postal Address: 13 Finnerty Pl. Kambah Canberra ACT 2902 Australia
+61 2 6282 6266