validating credit cards

Before I go re-inventing wheels, are there any available methods or JS functions to validate a credit-card number (i.e. compute the check-digit)?

Thanks,
Neale.

Hi Neale,

Here’s a link to a simple creditcard validation in javascript.
It’s HTML orientated, but you can easily copy paste the if statements into your own script.
http://www.shu.ac.uk/schools/cms/teaching/rh1/elearning/creditcard/credit_card_validation.htm

You can also use http://www.google.com and search for eg: “javascript creditcard validation”, giving you loads of examples!
(I’d like to encourage everyone who finds interesting (javascript)code on the net, to place a link on the forum… :) thanks )

Thanks for the feedback.

As you say, there are many available if only I had searched. Searching via Google for ‘javascript (creditcard OR “credit card”) validation’ returned many interesting possibilities, including: http://www.breakingpar.com/bkp/home.nsf … C70060A01B

That’s nice concise code and pretty close to what I’m looking for, except that:

  1. It needs to accomodate more cards types (starting with the Aussie “BankCard”).
  2. I suspect there’s a bug in that it allows card#s with dashes but doesn’t appear to account for these when computing the checksum.

Both of those should be fairly trivial to fix.

There’s another interesting example at http://javascript.about.com/library/scr … cvalid.htm and no doubt many more elsewhere.

IIRC, there was some discussion here about how to create a global method which can be called as a function from various form methods. Any pointers here?

Thanks,
Neale.