<input oninput="onInput(this)" type="text" value=""/>
var passwordReal = [];
function onInput(e) {
var value = Array.from(e.value);
// Allow copy
if (value.indexOf('●') < 0) {
this.passwordReal = value;
}
// If current array value is greater than temp array, get the last value just entered
// Otherwise, calculate to make 2 arrays equal
else if (value.length > this.passwordReal.length) {
passwordReal.push(value.pop());
} else {
passwordReal.splice(value.length, (passwordReal.length - value.length));
}
e.value = passwordReal.map(c => c.replace(/./gi, '●')).join('');
console.log(passwordReal.join(''));
}
Demo : https://jsfiddle.net/vwp8q720/9/
Latest comments (0)