A Javascript implementation of the Luhn Algorithm
This is a demonstration of my Javascript implementation of the Luhn algorithm for validating credit card numbers. You are welcome to test it out. This form does nothing with the data, even check for yourself if you want by Looking at the script.Keep in mind that this does not actually verify that a given credit card number has an account attached to it, just that it could.
I wrote this script to decrease the number of failed purchasing attempts due to typographical errors. Again, there is no actual validation of the credit card number. This algorithm simply checks to make sure that it could be a valid account number.
Demo
Simply type in the credit card number and the script will automatically check the internal checksum numbers for number correctness as you type.
Code Examaple
<script language="javascript" type="text/javascript" src="js/ccvalidate.js"></script> <form> <label for="ccnum">Credit Card Number</label> <input type="text" name="ccnum" id="ccnum" size="30" onkeyup=" if (ccValidate(this.value)){ document.ccvalidImg.src='images/yes.gif'; this.form.bank.value=ccBankId(this.value); } else { document.ccvalidImg.src='images/no.gif'; } " /> <img src="images/trans.gif" name="ccvalidImg" /> <input type="text" name="bank" value="" size="5" /> </form>