diff --git a/login.css b/login.css index 7ca40e3a..526de69b 100644 --- a/login.css +++ b/login.css @@ -43,6 +43,20 @@ body{ outline-color: #3692FF;; } +.error { + border:1px solid red; +} + + +.error-message, +.error-message-pw, +.error-message-nick, +.error-message-pwcheck { + outline-color: red; + color: red; + display: none; +} + .input::placeholder{ color: #9CA3AF; font-weight: 400; diff --git a/login.html b/login.html index 8f493b1c..fd6973dc 100644 --- a/login.html +++ b/login.html @@ -29,12 +29,14 @@
+
+
- +
간편 로그인하기 @@ -49,5 +51,6 @@ 회원가입 + diff --git a/login.js b/login.js new file mode 100644 index 00000000..385f3942 --- /dev/null +++ b/login.js @@ -0,0 +1,72 @@ +const emailInputElement = document.querySelector('#email'); +const pwInputElement = document.querySelector('#pw'); +const errorMessage = document.querySelector('.error-message'); +const pwErrorMessage = document.querySelector('.error-message-pw'); + +function emailForm(e) { + if (emailInputElement.value === '') { + emailInputElement.classList.add('error'); + errorMessage.textContent ="이메일을 입력해주세요." + errorMessage.style.display = 'block'; + } else if (!(emailInputElement.value.includes("@") + && emailInputElement.value.includes("."))) { + emailInputElement.classList.add('error'); + errorMessage.textContent ="잘못된 이메일 형식입니다." + errorMessage.style.display = 'block'; + }else{ + emailInputElement.classList.remove('error'); + errorMessage.style.display = 'none'; + } +} + +function pwForm(e) { + if (pwInputElement.value === '') { + pwInputElement.classList.add('error'); + pwErrorMessage.textContent ="비밀번호를 입력해주세요." + pwErrorMessage.style.display = 'block'; + } else if (pwInputElement.value.length < 8) { + pwInputElement.classList.add('error'); + pwErrorMessage.textContent ="비밀번호를 8자 이상 입력해주세요." + pwErrorMessage.style.display = 'block'; + }else{ + pwInputElement.classList.remove('error'); + pwErrorMessage.style.display = 'none'; + } +} + +function removeMessage(e){ + if(e.target.id === "email"){ + errorMessage.style.display = 'none'; + }else{ + pwErrorMessage.style.display = 'none'; + } +} + + +emailInputElement.addEventListener('blur', emailForm) +emailInputElement.addEventListener('focus', removeMessage) + +pwInputElement.addEventListener('blur', pwForm) +pwInputElement.addEventListener('focus', removeMessage) + +// ---------------------------------------------------------- + +const loginElement = document.querySelector("#login") + +function activateLogin(e){ + if(emailInputElement.classList.contains('error') + || pwInputElement.classList.contains('error')){ + loginElement.style.backgroundColor = "#9CA3AF" + + } else if(emailInputElement.value === '' || pwInputElement.value === ''){ + loginElement.style.backgroundColor = "#9CA3AF" + }else{ + loginElement.style.backgroundColor = "#3692FF" + } +} + +pwInputElement.addEventListener('blur', activateLogin) +emailInputElement.addEventListener('blur', activateLogin) + + + diff --git a/signup.html b/signup.html index b8e39101..a4860a7f 100644 --- a/signup.html +++ b/signup.html @@ -28,21 +28,25 @@
- + +
- + +
- + +
- +
+ diff --git a/signup.js b/signup.js new file mode 100644 index 00000000..883884ea --- /dev/null +++ b/signup.js @@ -0,0 +1,131 @@ +let signupValid = false + +//ID 선택하기 +const emailInputElement = document.getElementById('email'); +const nickInputElement = document.getElementById('nickname'); +const pwInputElement = document.getElementById('pw'); +const pwCheckInputElement = document.getElementById('pwcheck'); +const errorMessage = document.querySelector('.error-message'); +const nickErrorMessage = document.querySelector('.error-message-nick'); +const pwErrorMessage = document.querySelector('.error-message-pw'); +const pwCheckErrorMessage = document.querySelector('.error-message-pwcheck'); +const signupElement = document.querySelector('.login-btn') + + + + + +function emailForm(e) { + if (emailInputElement.value === '') { + emailInputElement.classList.add('error'); + errorMessage.textContent = "이메일을 입력해주세요" + errorMessage.style.display = 'block'; + } else if (!(emailInputElement.value.includes("@") + && emailInputElement.value.includes("."))) { + emailInputElement.classList.add('error'); + errorMessage.textContent ="잘못된 이메일 형식입니다." + errorMessage.style.display = 'block'; + }else{ + emailInputElement.classList.remove('error'); + errorMessage.style.display = 'none'; + }; +}; + +function nickForm(e) { + if (nickInputElement.value === '') { + nickInputElement.classList.add('error'); + nickErrorMessage.textContent = "닉네임을 입력해주세요." + nickErrorMessage.style.display = "block"; + } else { + nickInputElement.classList.remove('error'); + nickErrorMessage.style.display = 'none'; + }; +}; + +function pwForm(e) { + if (pwInputElement.value === '') { + pwInputElement.classList.add('error'); + pwErrorMessage.textContent ="비밀번호를 입력해주세요." + pwErrorMessage.style.display = 'block'; + } else if (pwInputElement.value.length < 8) { + pwInputElement.classList.add('error'); + pwErrorMessage.textContent ="비밀번호를 8자 이상 입력해주세요." + pwErrorMessage.style.display = 'block'; + }else{ + pwInputElement.classList.remove('error'); + pwErrorMessage.style.display = 'none'; + }; +}; + +function removeMessage(e){ + if(e.target.id === "email"){ + errorMessage.style.display = 'none'; + } else if(e.target.id === "nickname"){ + nickErrorMessage.style.display = 'none'; + } else if(e.target.id === "pw"){ + pwErrorMessage.style.display = 'none'; + } else{ + pwCheckErrorMessage.style.display = 'none'; + }; +}; + +function pwValid(e) { + if (!(pwInputElement.value === pwCheckInputElement.value)) { + pwCheckInputElement.classList.add('error'); + pwCheckErrorMessage.textContent = "비밀번호가 일치하지 않습니다.." + pwCheckErrorMessage.style.display = 'block'; + }else{ + pwCheckInputElement.classList.remove('error'); + pwCheckErrorMessage.style.display = 'none'; + }; +} + +function activateSignup(e){ + if( + emailInputElement.classList.contains('error') + || nickInputElement.classList.contains('error') + || pwInputElement.classList.contains('error') + || pwCheckInputElement.classList.contains('error') + ) { + signupElement.style.backgroundColor = "#9CA3AF" + } else if ( + emailInputElement.value ==='' + || nickInputElement.value ==='' + || pwInputElement.value ==='' + || pwCheckInputElement.value === '' + ) { + signupElement.style.backgroundColor = "#9CA3AF" + } else { + signupElement.style.backgroundColor = "#3692FF" + signupValid = true + } +} + + + +emailInputElement.addEventListener('blur', emailForm); +nickInputElement.addEventListener('blur', nickForm); +pwInputElement.addEventListener('blur', pwForm); +pwCheckInputElement.addEventListener('blur', pwValid); + +emailInputElement.addEventListener('focus',removeMessage) +nickInputElement.addEventListener('focus',removeMessage) +pwInputElement.addEventListener('focus',removeMessage) +pwCheckInputElement.addEventListener('focus',removeMessage) + + +emailInputElement.addEventListener('blur', activateSignup) +nickInputElement.addEventListener('blur', activateSignup) +pwInputElement.addEventListener('blur', activateSignup) +pwCheckInputElement.addEventListener('blur', activateSignup) + +pwInputElement.addEventListener('change',pwValid); + + +function signupButton(e){ + if(signupValid){ + window.location.href = "/login" + } +} + +signupElement.addEventListener("click",signupButton) \ No newline at end of file