-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (32 loc) · 1.21 KB
/
app.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
43
44
45
46
// show password toggler
let showPasswordBtn = document.querySelector('.show-password');
let passwordInp = document.querySelector('.password-input');
let passwordChecklist = document.querySelectorAll('.list-item');
showPasswordBtn.addEventListener('click', () => {
// toggle icon
showPasswordBtn.classList.toggle('fa-eye');
showPasswordBtn.classList.toggle('fa-eye-slash');
passwordInp.type = passwordInp.type === 'password' ? 'text' : 'password';
})
// string password validation
let validationRegex = [
{ regex: /.{8,}/ }, // min 8 letters,
{ regex: /[0-9]/ }, // numbers from 0 - 9
{ regex: /[a-z]/ }, // letters from a - z (lowercase)
{ regex: /[A-Z]/}, // letters from A-Z (uppercase),
{ regex: /[^A-Za-z0-9]/} // special characters
]
passwordInp.addEventListener('keyup', () => {
validationRegex.forEach((item, i) => {
let isValid = item.regex.test(passwordInp.value);
if(isValid) {
passwordChecklist[i].classList.add('checked');
} else{
passwordChecklist[i].classList.remove('checked');
}
})
})
const chk = document.getElementById('chk')
chk.addEventListener('change', () => {
document.body.classList.toggle('dark')
})