-
Notifications
You must be signed in to change notification settings - Fork 37
[이민서] Sprint4 #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kich555
merged 3 commits into
codeit-bootcamp-frontend:Basic-이민서
from
LMS10:Basic-이민서-sprint4
Nov 17, 2024
The head ref may contain hidden characters: "Basic-\uC774\uBBFC\uC11C-sprint4"
Merged
[이민서] Sprint4 #152
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ document.addEventListener("DOMContentLoaded", () => { | |
| let isNicknameValid = false; | ||
| let isPasswordValid = false; | ||
| let isPasswordConfirmationValid = false; | ||
|
|
||
| const emailRegex = /^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/; | ||
|
|
||
| const loginForm = document.querySelector('.login-form'); | ||
| const signupForm = document.querySelector('.signup-form'); | ||
|
|
@@ -27,14 +29,12 @@ document.addEventListener("DOMContentLoaded", () => { | |
| } | ||
|
|
||
| // 이메일 형식 유효성 검사 | ||
| function validateEmailString(email) { | ||
| const emailRegex = /^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/; | ||
| function isEmailValidFormat(email) { | ||
| return emailRegex.test(email); | ||
| } | ||
|
|
||
| // 이메일 필드 유효성 검사 | ||
| function checkEmailValidity() { | ||
| // 입력 필드 선택 후 아무것도 입력 안 하고 필드 focus out하는 경우 걸러내기 위함 | ||
| const emailValue = emailInput.value.trim(); | ||
|
|
||
| // 오류 메세지 및 입력 필드 상태 초기화 | ||
|
|
@@ -44,7 +44,7 @@ document.addEventListener("DOMContentLoaded", () => { | |
|
|
||
| if (!emailValue) { | ||
| showError(emailInput, "email-empty-error"); | ||
| } else if (!validateEmailString(emailValue)) { | ||
| } else if (!isEmailValidFormat(emailValue)) { | ||
| showError(emailInput, "email-invalid-error"); | ||
| } else { | ||
| isEmailValid = true; | ||
|
|
@@ -144,18 +144,38 @@ document.addEventListener("DOMContentLoaded", () => { | |
| passwordConfirmationInput.addEventListener("input", checkPasswordConfirmationValidity); | ||
| } | ||
|
|
||
| // 폼 제출 전 이벤트 리스너 제거 | ||
| function removeEventListeners() { | ||
| if (emailInput) { | ||
| emailInput.removeEventListener("focusout", checkEmailValidity); | ||
| } | ||
| if (nicknameInput) { | ||
| nicknameInput.removeEventListener("focusout", checkNicknameValidity); | ||
| } | ||
| if (passwordInput) { | ||
| passwordInput.removeEventListener("focusout", checkPasswordValidity); | ||
| passwordInput.removeEventListener("input", checkPasswordValidity); | ||
| } | ||
| if (passwordConfirmationInput) { | ||
| passwordConfirmationInput.removeEventListener("focusout", checkPasswordConfirmationValidity); | ||
| passwordConfirmationInput.removeEventListener("input", checkPasswordConfirmationValidity); | ||
| } | ||
| } | ||
|
|
||
| // 이후 기능 추가 후 수정 (현재는 단순히 특정 페이지로 이동) | ||
| // 로그인 폼 처리 | ||
| if (loginForm) { | ||
| loginForm.addEventListener("submit", (event) => { | ||
| event.preventDefault(); | ||
| removeEventListeners(); // 폼 제출 시 이벤트 제거 | ||
| window.location.href = "/index.html"; | ||
|
Comment on lines
+194
to
195
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
하지만 연습이라는 의미에서는 좋습니다~ |
||
| }); | ||
| } | ||
| // 회원가입 폼 처리 | ||
| if (signupForm) { | ||
| signupForm.addEventListener("submit", (event) => { | ||
| event.preventDefault(); | ||
| removeEventListeners(); // 폼 제출 시 이벤트 제거 | ||
| window.location.href = "/login.html"; | ||
| }); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙋 지금 함수도 나쁘진 않은데요 ㅎ 아래와 같이 코드를 데이터로 추상화하여 로직을 일반화하고, 데이터만 변경하여 동작을 조절할 수 있게 한다면 보다 유연하고 가독성도 좋은 코드가 될 수 있지 않을까요 ㅎ