-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
132 lines (115 loc) · 3.75 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import "./style.scss";
let checkbox = document.querySelector('.container .form input[type="checkbox"]');
let password = document.querySelector('.container .form input[type="password"]');
let close = document.querySelector("#modal button");
let form = document.querySelector(".container .form form");
let isCorrect = false;
let isCorrectPassword = [false, false, false];
checkbox.onclick = (e) => {
if (e.target.checked === true) {
password.type = "text";
} else {
password.type = "password";
}
};
form.addEventListener("submit", (e) => {
let markEmail = document.querySelector("#modal section p mark#email");
let markName = document.querySelector("#modal section p mark#name");
if (e.target[0].value === "") {
e.target[0].nextElementSibling.style.display = "block";
e.target[0].nextElementSibling.nextElementSibling.style.maxHeight = "1.3rem";
e.target[0].nextElementSibling.nextElementSibling.style.opacity = 1;
isCorrect = false;
} else {
isCorrect = true;
}
if (e.target[1].value === "") {
e.target[1].nextElementSibling.style.display = "block";
e.target[1].nextElementSibling.nextElementSibling.style.maxHeight = "1.3rem";
e.target[1].nextElementSibling.nextElementSibling.style.opacity = 1;
isCorrect = false;
} else {
isCorrect = true;
}
if (e.target[2].value === "") {
e.target[2].nextElementSibling.style.display = "block";
e.target[2].nextElementSibling.nextElementSibling.style.maxHeight = "1.3rem";
e.target[2].nextElementSibling.nextElementSibling.style.opacity = 1;
isCorrect = false;
} else {
isCorrect = true;
}
if (e.target[3].value === "") {
e.target[3].nextElementSibling.style.maxHeight = "1.3rem";
e.target[3].nextElementSibling.style.opacity = 1;
isCorrect = false;
}
e.preventDefault();
e.stopPropagation();
let isCorrectPasswordArray = isCorrectPassword.every((element) => {
if (element === true) {
return true;
} else {
return false;
}
});
if (isCorrect && isCorrectPasswordArray) {
let emaiResult = e.target[2].value;
let nameResult = `${e.target[0].value} ${e.target[1].value}`;
e.target[0].value = "";
e.target[1].value = "";
e.target[2].value = "";
e.target[3].value = "";
markEmail.innerHTML = emaiResult;
markName.innerHTML = nameResult;
modal.showModal();
return true;
} else {
return false;
}
});
password.addEventListener("keyup", (even) => {
let li = document.querySelectorAll(".container .form label li");
if (containsSomething(even.target.value, "[A-Z]")) {
li[0].style.color = "green";
li[0].style.setProperty("--icon-error", "url(../images/icons8-checkmark.svg)");
isCorrectPassword[0] = true;
} else {
li[0].style.color = "hsl(0, 100%, 74%)";
li[0].style.setProperty("--icon-error", "url(../images/icon-error-pw.svg)");
isCorrectPassword[0] = false;
}
if (containsSomething(even.target.value, "[0-9]")) {
li[1].style.color = "green";
li[1].style.setProperty("--icon-error", "url(../images/icons8-checkmark.svg)");
isCorrectPassword[1] = true;
} else {
li[1].style.color = "hsl(0, 100%, 74%)";
li[1].style.setProperty("--icon-error", "url(../images/icon-error-pw.svg)");
isCorrectPassword[1] = false;
}
if (containsSomething(even.target.value, "[?<!>@#$%^&*]")) {
li[2].style.color = "green";
li[2].style.setProperty("--icon-error", "url(../images/icons8-checkmark.svg)");
isCorrectPassword[2] = true;
} else {
li[2].style.color = "hsl(0, 100%, 74%)";
li[2].style.setProperty("--icon-error", "url(../images/icon-error-pw.svg)");
isCorrectPassword[2] = false;
}
});
function containsSomething(word, regexp) {
let i = 0;
let bool = false;
let regxp = new RegExp(regexp);
while (i < word.length) {
if (regxp.test(word.charAt(i))) {
bool = true;
}
i++;
}
return bool;
}
close.addEventListener("click", (a) => {
modal.close();
});