I have the following code for Password Validation to test different cases and add valid and invalid classes to show the correctness in my HTML file.But I have a lot of if-else blocks to verify all the conditions. I tried implementing with switch statement but not luck. Any leads on how this can be implemented with a lot of if-else conditions. Thanks!
var pwdCheck = (str) => {
var upper = /[A-Z]/g,
numbers = /[0-9]/g,
lower = /[a-z]/g;
if (str.match(upper)) {
uppercase.classList.remove("invalid");
uppercase.classList.add("valid");
} else {
uppercase.classList.remove("valid");
uppercase.classList.add("invalid");
}
// Numbers //
if (str.match(numbers)) {
numeric.classList.remove("invalid");
numeric.classList.add("valid");
} else {
numeric.classList.remove("valid");
numeric.classList.add("invalid");
}
}