PreFormatted Credit Card Numbers
The following javascript code will preformat the creditcard number with dashes.
The function is called in the keypress event of the text box for entering the credit card. For each keypress to enter the digit the fucntion will check if the position id 5, or 10, or 15 it will add a dash to it.
<script>
function onType(formObject) {
var len = formObject.cc_no.value.length +1;
//insert a dash at these positions
if ((len % 5) == 0) {
formObject.cc_no.value = formObject.cc_no.value + “-”;
}
}
</script>
<form>
<input type=”text” name=”cc_no” maxlength=”19″ onkeypress=”onType(this.form)”>
</form>
