views:

301

answers:

3

Does anyone have a library or JavaScript snippet to verify the check digit of credit cards before the user hits Submit?

+1  A: 

I have found one with demo on google for

  • MasterCard
  • Visa
  • American Express
  • Diners Club
  • Discover
  • enRoute
  • JCB

http://javascript.internet.com/forms/val-credit-card.html

codemeit
+4  A: 

The jQuery Validation Plugin has a method for validating credit card numbers.

There are other specific scripts:

Most of them use the Luhn algorithm.

CMS
A: 

You can use this function if you're not already using the jQuery plugin. It's based on the Luhn algorithm and is tolerant of spaces or dashes so should work for most data entry cases you would need it for.

http://af-design.com/blog/2010/08/18/validating-credit-card-numbers/

Erik Giberti