generated from tod/odin-webpack-template
Constraint API: setCustomValidity for password, and small fixes
This commit is contained in:
parent
84cb547df8
commit
ec621d42b3
|
@ -19,18 +19,20 @@ function checkPasswordMatch() {
|
||||||
passwordInput.value === ""
|
passwordInput.value === ""
|
||||||
) {
|
) {
|
||||||
passwordMatch.style.backgroundColor = "";
|
passwordMatch.style.backgroundColor = "";
|
||||||
|
passwordConfirmInput.setCustomValidity("Passwords don't match");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
passwordMatch.style.backgroundColor = "#4b4";
|
passwordMatch.style.backgroundColor = "#4b4";
|
||||||
|
passwordConfirmInput.setCustomValidity("");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPasswordRequirement(e, regex, element) {
|
function checkPasswordRequirement(regex, requirementElement) {
|
||||||
if (e.value.search(regex) >= 0) {
|
if (passwordInput.value.search(regex) >= 0) {
|
||||||
element.style.backgroundColor = "#4b4";
|
requirementElement.style.backgroundColor = "#4b4";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
element.style.backgroundColor = "";
|
requirementElement.style.backgroundColor = "";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,23 +43,18 @@ function checkPasswordValidity() {
|
||||||
} else {
|
} else {
|
||||||
passwordLength.style.backgroundColor = "";
|
passwordLength.style.backgroundColor = "";
|
||||||
}
|
}
|
||||||
const lowercase = checkPasswordRequirement(
|
const lowercase = checkPasswordRequirement(/[a-z]/, passwordLowercase);
|
||||||
passwordInput,
|
const uppercase = checkPasswordRequirement(/[A-Z]/, passwordUppercase);
|
||||||
/[a-z]/,
|
const number = checkPasswordRequirement(/\d/, passwordNumber);
|
||||||
passwordLowercase,
|
const special = checkPasswordRequirement(/[#?!@$%^&*-]/, passwordSpecial);
|
||||||
);
|
const suitsRequirements =
|
||||||
const uppercase = checkPasswordRequirement(
|
length && lowercase && uppercase && number && special;
|
||||||
passwordInput,
|
if (suitsRequirements) {
|
||||||
/[A-Z]/,
|
passwordInput.setCustomValidity("");
|
||||||
passwordUppercase,
|
} else {
|
||||||
);
|
passwordInput.setCustomValidity("Password does not meet requirements");
|
||||||
const number = checkPasswordRequirement(passwordInput, /\d/, passwordNumber);
|
}
|
||||||
const special = checkPasswordRequirement(
|
return suitsRequirements;
|
||||||
passwordInput,
|
|
||||||
/[#?!@$%^&*-]/,
|
|
||||||
passwordSpecial,
|
|
||||||
);
|
|
||||||
return length && lowercase && uppercase && number && special;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { checkPasswordValidity, checkPasswordMatch };
|
export { checkPasswordValidity, checkPasswordMatch };
|
||||||
|
|
Loading…
Reference in New Issue