-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
26 lines (24 loc) · 845 Bytes
/
script.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
let password = document.getElementById('password');
let confirmPassword = document.getElementById('confirm_password');
let passwords = document.querySelectorAll('input[type="password"]');
function markPasswordInvalid() {
password.setCustomValidity("Passwords do not match");
passwords.forEach((passwordField) => {
passwordField.classList.add('error');
})
}
function markPasswordValid() {
password.setCustomValidity("");
passwords.forEach((passwordField) => {
passwordField.classList.remove('error');
})
}
passwords.forEach((passwordField) => {
passwordField.addEventListener('keyup', () => {
if (password.value !== confirmPassword.value) {
markPasswordInvalid();
} else if (password.value === confirmPassword.value) {
markPasswordValid();
}
})
})