-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidarSenha.js
42 lines (34 loc) · 1.23 KB
/
validarSenha.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function validateForm() {
const passwordInput = document.getElementById("password");
const errorMessage = document.getElementById("error-message");
const password = passwordInput.value;
const hasUpperCase = /[A-Z]/.test(password);
const hasSpecialChar = /[!@#$%^&*()_+{}\[\]:;<>,.?~\\-]/.test(password);
const isLongEnough = password.length >= 8;
let errors = [];
if (!hasUpperCase) {
errors.push("Pelo menos uma letra maiúscula");
}
if (!hasSpecialChar) {
errors.push("Pelo menos um caractere especial");
}
if (!isLongEnough) {
errors.push("Pelo menos 8 caracteres");
}
if (errors.length > 0) {
errorMessage.innerHTML =
"Corrija os seguintes erros:<br>" + errors.join("<br>");
errorMessage.style.marginTop = "-15px";
errorMessage.style.marginBottom = "10px";
errorMessage.style.color = "red";
passwordInput.style.borderColor = "red";
passwordInput.style.borderWidth = "3px";
return false; // Impede o envio do formulário
} else {
errorMessage.innerHTML = "";
errorMessage.style.color = "transparent";
// Redireciona o usuário para a página de boas-vindas
window.location.href = "welcome.html";
return false; // Impede o envio do formulário
}
}