I am trying to mask all the numbers in SSN field to * while keeping user only enter numeric values and formatting the SSN with dashes.
Here is a fiddle link:
https://jsfiddle.net/7f8p83am/
$('#ssn').keyup(function() {
var val = this.value.replace(/\D/g, '');
var newVal = '';
var sizes = [3, 2, 4];
var maxSize = 10;
for (var i in sizes) {
if (val.length > sizes[i]) {
newVal += val.substr(0, sizes[i]) + '-';
val = val.substr(sizes[i]);
} else {
break;
}
}
newVal += val;
this.value = newVal;
});
Obviously, the replace is getting rid of *. Any ideas on how to do this?
thanks in advance.