Credit Card Validation
There’s an excellent JavaScript validation tool over Position Absolute which uses jQuery. However it doesnt provide any Credit Card validation and I needed some.
The standard test for a correct Credit Card number is to check it using the Luhn Formula. It’s straight forward to use and well documented and not that hard to do in JavaScript. So I dove into the code from Position Absolute and extended it directly.
You can download the amended file here: http://howboring.com/linkedfiles/jquery.validationEngine.js.zip
Installation:
Unzip the file and just replace your existing jquery.validationEngine.js file.
How to use it:
I added a validator called luhnCC. It works exactly the same as the existing mechanisms, so you just add a new class: class=”validate[luhnCC]” to your input element. Your final input element might look like this:
<input id=”creditcard” name=”creditcard” type=”text” class=”validate[luhnCC]“ />
There are a few more things I could do. I’ll probably add in some sort of Data-Mask as well as the facility to validate only certain types of cards. It’s basic as it stands but it might help someone out.
If you experience any problems or have questions please leave a note in the comments.