How do I apply mask in the input field, when the user type instead of the numbers / letters I want to appear in this input field the special characters (*). Example: 999 ****** 99.
How do I apply mask in the input field, when the user type instead of the numbers / letters I want to appear in this input field the special characters (*). Example: 999 ****** 99.
I found this answer in SOEN ( link ). You can adapt to your reality, it does pretty much what you want.
var ssn = document.getElementById('ssn');
ssn.addEventListener('input', ssnMask, false);
var ssnFirstFive = "";
var secondHalf = "";
var fullSSN = "";
function ssnMask(){
if (ssn.value.length <= 5){
ssn.type = 'password';
}
else{
detectChanges();
secondHalf = ssn.value.substring(5);
ssn.type = 'text';
ssn.value = "•••••";
ssn.value += secondHalf;
fullSSN = ssnFirstFive + secondHalf;
}
}
function detectChanges() {
for (var i = 0; i < 5; i++){
if (ssn.value[i] != "•"){
ssnFirstFive = ssnFirstFive.substring(0, i) + ssn.value[i] + ssnFirstFive.substring(i+1);
}
}
}
<input type="password" id="ssn" maxlength=9 />