Here I use a regular expression pattern to mask the last 4 digits for a credit card number
$('#ccnumber').html(ccnbr); //ccnumber refers to div ID $('#ccnumber').text(function(_,val) { return val.replace(/\d{12}(\d{4})/, "************$1"); });
It applies only to 16-digit credit card numbers. But I need to mask the incoming numbers (maybe 10 or 11) by * and show the last 4 digits. Is this possible in javascript / jQuery?
JSFIDDLE
javascript jquery regex
UI_Dev
source share