Show some content of textbox as * using jquery [Resolved]

Posted by Allemahesh under jQuery on 10/23/2015 | Points: 10 | Views : 1521 | Status : [Member] [MVP] | Replies : 3
I need to save the credit card number form UI to database and I am taking this number form text box.
But while taking the card number form textbox, it should be in the below format.
Say my credit card number is 4859 4752 4856 1586 , then I need to display this number in text box as.

4859 47** **** 1586

I need this in JQUERY.
Can you any one help me to do this.




Responses

Posted by: Rajnilari2015 on: 10/23/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Use the same code as I have shown above (note the use of "originalValue " variable which is use for restoring back the original value)

var originalValue = "";

$(document).ready(function() {

$("#txtCCN").keyup(function(e) {
originalValue +=String.fromCharCode(e.which);
var CCNValue = $(this).val();
$(this).val(CCNValue.substring(0, 7) + CCNValue.substring(7, 15).replace(/[0-9]/g , "*") + CCNValue.substring(15));
});
});

------------HTML-----------------------
Credit Card number: <input type="text" id="txtCCN" maxlength=19 />


--
Thanks & Regards,
RNA Team

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 10/23/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
Don't understand why you need a JQuery for this when you need a replace function with a substring

var CCN = "4859 4752 4856 1586"; 
var maskedCCN = CCN.substring(0,7) + CCN.substring(7,15).replace(/[0-9]/g , "*") + CCN.substring(15);
alert("Original CCN : " + CCN);
alert("Masked CCN : " + maskedCCN);


--
Thanks & Regards,
RNA Team

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 10/23/2015 [Member] [MVP] Silver | Points: 25

Up
0
Down
Thank you for you replay.
But I need to convert number to '*' when user enter the values one after the other may be by using keydown() event and finally need to show the 4859 47** **** 1586 in the textbox.
But when I read this form code behind, the I must be able to read it as back i.e. 4859 4752 4856 1586

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response