-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleSignUp.js
More file actions
266 lines (201 loc) · 6.66 KB
/
Copy pathsimpleSignUp.js
File metadata and controls
266 lines (201 loc) · 6.66 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
document.addEventListener("DOMContentLoaded", function() {
// 페이지 로딩이 완료된 후 실행되어야 하는 초기화 코드
checkPw1();
checkNumber();
joinDone();
});
// 유효성 검사
function isValidEmail(email) {
return email.includes('@');
}
function isValidName(name) {
return name.trim().length > 0; // 이름이 빈 문자열이 아니어야 함
}
function isValidPassword(pw) {
return pw.length > 0;
}
function passwordsMatch(pw1, pw2) {
return pw1 === pw2;
}
function isValidPhone(phone1, phone2, phone3) {
return phone1.length === 3 && phone2.length === 4 && phone3.length === 4;
}
function checkAllFieldsValid() {
let email = document.getElementById('email').value;
let user = document.getElementById('user').value;
let pw1 = document.getElementById('pw1').value;
let pw2 = document.getElementById('pw2').value;
let phone1 = document.getElementById('phone1').value;
let phone2 = document.getElementById('phone2').value;
let phone3 = document.getElementById('phone3').value;
let sendButton = document.getElementById('sendButton');
const isAllValid =
isValidEmail(email) &&
isValidName(user) &&
isValidPassword(pw1) &&
passwordsMatch(pw1, pw2) &&
isValidPhone(phone1, phone2, phone3);
sendButton.disabled = !isAllValid;
if (sendButton.disabled === true) {
document.getElementById('token').innerHTML = '000000'
document.getElementById('token').style.color = '#727272';
checkNumber()
}
}
// ####
const checkEmail = () => {
let email = document.getElementById('email').value
let emailWrong = document.getElementById('emailWrong');
let emailInput = document.getElementById('email');
if (email.includes('@') || !email) {
emailInput.classList.remove('error');
emailWrong.innerHTML = ''
emailWrong.style.marginBottom = '0px';
}
else {
emailInput.classList.add('error');
emailWrong.innerHTML = '이메일 형식이 아닙니다. 다시 입력해 주세요.';
emailWrong.style.marginBottom = '20px';
}
checkAllFieldsValid();
};
const checkPw1 = () => {
let pw1 = document.getElementById('pw1').value;
let pw2Input = document.getElementById('pw2');
let pw2 = document.getElementById('pw2').value;
if (!pw1) {
pw2Input.disabled = true;
pw2Input.classList.remove('error');
pw2Wrong.innerText= '';
pw2Input.value = '';
pw2Wrong.style.marginBottom = '0px';
}
else {
pw2Input.disabled = false;
}
if (pw2.length > 0) {
checkPw2();
}
checkAllFieldsValid();
};
const checkPw2 = () => {
let pw1 = document.getElementById('pw1').value;
let pw2 = document.getElementById('pw2').value;
let pw2Wrong = document.getElementById('pw2Wrong');
let pw2Input = document.getElementById('pw2');
if (pw1 !== pw2) {
pw2Input.classList.add('error');
pw2Wrong.innerHTML = '비밀번호가 다릅니다. 다시 입력해 주세요.';
pw2Wrong.style.marginBottom = '20px';
}
else {
pw2Input.classList.remove('error');
pw2Wrong.innerHTML = '';
pw2Wrong.style.marginBottom = '0px';
}
checkAllFieldsValid();
};
const changeFocus1 = () => {
let phone1 = document.getElementById('phone1').value
if(phone1.length === 3){
document.getElementById('phone2').focus()
}
checkAllFieldsValid();
};
const changeFocus2 = () => {
let phone2 = document.getElementById('phone2').value
if(phone2.length === 4){
document.getElementById('phone3').focus()
}
checkAllFieldsValid();
};
const changeFocus3 = () => {
let phone3 = document.getElementById('phone3');
if(phone3.value.length === 4){
phone3.blur();
}
checkAllFieldsValid();
};
const sendNumber = () => {
const token = String(Math.floor(Math.random() * 1000000)).padStart(6, "0")
document.getElementById('token').innerHTML = token
document.getElementById('token').style.color = '#0068FF';
isNumberDone = false;
};
const checkNumber = () => {
let doneButton = document.getElementById('doneButton');
let token = document.getElementById('token');
let tokenColor = window.getComputedStyle(token).color;
// 위의 코드에서 window.getComputedStyle를 사용하여 계산된 스타일 값을 가져옵니다.
// CSS의 hex 색상 값은 RGB 값으로 변환되므로, 해당 RGB 값과 비교를 합니다.
if (tokenColor !== 'rgb(0, 104, 255)') {
doneButton.disabled = true;
clearInterval(timer);
isNumberDone = false
doneButton.classList.remove('done')
}
else {
doneButton.disabled = false;
isStarted = false;
}
joinDone()
};
let isStarted = false;
let timer
let isNumberDone = false;
let isRegionDone = false;
let isGenderDone = false;
const checkTimer = () => {
let doneButton = document.getElementById('doneButton');
if(isStarted === false && doneButton.disabled === false){
clearInterval(timer); // 기존 타이머 중지
isStarted = true;
doneButton.classList.remove('done');
isNumberDone = false;
let time = 180;
timer = setInterval(function(){
if(time >= 0){
let min = Math.floor(time / 60);
let sec = String(time % 60).padStart(2, "0");
document.getElementById('timer').innerHTML = `${min}:${sec}`;
time = time - 1;
}
else{
document.getElementById('doneButton').disabled = true;
isStarted = false;
clearInterval(timer);
}
},1000)
}
};
const doneNumber = () => {
let doneButton = document.getElementById('doneButton');
doneButton.classList.add('done');
isNumberDone = true;
clearInterval(timer);
joinDone();
};
const checkRegion = () => {
let region = document.getElementById('region').value;
isRegionDone = true
joinDone();
};
const checkGender = () => {
isGenderDone = true
joinDone();
};
const joinDone = () => {
let joinButton = document.getElementById('joinButton');
console.log("isGenderDone:", isGenderDone); // 값 확인
console.log("isNumberDone:", isNumberDone); // 값 확인
console.log("isRegionDone:", isRegionDone); // 값 확인
if(isGenderDone === true && isNumberDone === true && isRegionDone === true) {
joinButton.disabled = false;
}
else {
joinButton.disabled = true;
}
};
const clickJoin = () => {
alert("가입을 축하드립니다!! 🥳");
};