Masking the Credit Card Numbers using JQuery - Solution1

Posted by Rajnilari2015 under jQuery category on | Points: 40 | Views : 2738
Suppose we have a textbox and we have to mask (with asterisk (*) character) a portion of the string (which is a credit card number) when user enter the values one after the other.
That means , if the user enters XXXX XXXX XXXX XXXX , the output will be XXXX XX** **** XXXX where X represents any valid number.
The below program will help to do so

<script type="text/javascript" src=""></script>
$(document).ready(function() {
$("#txtCCN").keyup(function(e) {
var CCNValue = $(this).val();
$(this).val(CCNValue.substring(0, 7) + CCNValue.substring(7, 15).replace(/[0-9]/g , "*") + CCNValue.substring(15));
Credit Card number: <input type="text" id="txtCCN" maxlength=19 />

Comments or Responses

Login to post response