0
How can I revise this code. It works but how can it be made better as far as javascript only.
3 ответов
+ 2
function checkValid() {
let inp = usrInput.value,
num = inp.replace(/\D+/g,''),
spe = inp.replace(/[^!#@*&%]+/g,'');
if (inp) {
if (inp.length<7 || num.length<2 || spe.length<1) {
output.innerHTML = "Please enter a password that meets the above requirements.";
form.reset();
} else {
output.innerHTML = "digit count: "+num.length+"<br>special char count: "+spe.length;
}
}
else output.innerHTML = "Please enter a password";
}
+ 1
ODLNT yes, you're right: thank you... now corrected ;)
0
Use regex. Its simple and efficient.