PreFormatted Credit Card Numbers

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>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.