-
Notifications
You must be signed in to change notification settings - Fork 26
Basic-류정훈-sprint4 #87
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
The head ref may contain hidden characters: "Basic-\uB958\uC815\uD6C8-Sprint4"
Changes from all commits
eecc226
ec4fb6f
6a35b1d
209f2e0
6a679e2
669183e
98160c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||||||
| const emailInput = document.getElementById("email"); | ||||||||||
| const passwordInput = document.getElementById("password"); | ||||||||||
| const emailError = document.getElementById("emailError"); | ||||||||||
| const passwordError = document.getElementById("passwordError"); | ||||||||||
|
|
||||||||||
| const button = document.getElementById("btn"); | ||||||||||
| const pwtoggle = document.getElementById("pwtoggle"); | ||||||||||
| const pwon = document.getElementById("pwOn"); | ||||||||||
| const pwoff = document.getElementById("pwOff") | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||||||||||
| const error={ | ||||||||||
| email : 0, | ||||||||||
| password : 0, | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| emailInput.addEventListener("focusout",function() { | ||||||||||
| const value = emailInput.value.trim(); | ||||||||||
| if (value==""){ | ||||||||||
| emailError.textContent = "이메일을 입력해 주세요"; | ||||||||||
| emailError.style.display = "block"; | ||||||||||
| emailInput.classList.add("errorborder"); | ||||||||||
| error.email =0; | ||||||||||
| }else if(!emailPattern.test(value)){ | ||||||||||
| emailError.textContent = "잘못된 이메일 형식입니다."; | ||||||||||
| emailError.style.display = "block"; | ||||||||||
| emailInput.classList.add("errorborder"); | ||||||||||
|
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. 클래스 이름에 띄어쓰기가 명확하지 않은 것 같군요 ..!
Suggested change
네이밍 컨벤션을 한 번 살펴보면 좋을 것 같아요 ! 😉 |
||||||||||
| error.email =0; | ||||||||||
| }else{ | ||||||||||
| emailError.style.display="none" | ||||||||||
| emailInput.classList.remove("errorborder"); | ||||||||||
| error.email =1; | ||||||||||
|
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. 에러가 존재한다면
|
||||||||||
| error.email =1; | |
| error.email = true; |
만약 그렇다면 Number 타입보다 Boolean 타입을 사용하는 것이 메모리 측면과 코드 의사 측면에서 더 유리할 것으로 사료됩니다 😇
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.
오잉? 혹시 곱하기가 "두 조건이 참일 경우"를 의미하는걸까요?
만약 boolean으로 바뀐다면 다음과 같이 바꿀 수 있겠네요 !:
| const validcheck = error.email * error.password; | |
| const validcheck = error.email && error.password; |
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.
또한 해당 변수도 마찬가지로 네이밍 컨벤션을 따르는게 좋을 것 같아요 !
| const validcheck = error.email * error.password; | |
| const validCheck = error.email && error.password; |
그리고 만약 boolean일 경우 is-, has-와 같이 의문으로 짓는 경우가 많습니다 !
정훈님과 같은 경우 isValidFormData와 같이 될 수 있겠네요 😉
|
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. (심화/생각해보기)
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| const emailInput =document.getElementById("email"); | ||
| const nicknameInput = document.getElementById("nickname"); | ||
| const passwordInput = document.getElementById("password"); | ||
| const passwordcheckInput = document.getElementById("passwordcheck"); | ||
|
|
||
| const emailError =document.getElementById("emailError"); | ||
| const nicknameError = document.getElementById("nicknameError"); | ||
| const passwordError = document.getElementById("passwordError"); | ||
| const passwordcheckError = document.getElementById("passwordcheckError"); | ||
| const pwtoggle = document.getElementById("pwtoggle"); | ||
| const pwon = document.getElementById("pwOn"); | ||
| const pwoff = document.getElementById("pwOff") | ||
| const pctoggle = document.getElementById("pctoggle"); | ||
| const pcon = document.getElementById("pcOn"); | ||
| const pcoff = document.getElementById("pcOff") | ||
|
|
||
| const button = document.getElementById("btn"); | ||
|
|
||
|
|
||
|
|
||
| const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
| const error={ | ||
| email : 0, | ||
| nickname : 0, | ||
| password : 0, | ||
| passwordcheck : 0, | ||
| }; | ||
| emailInput.addEventListener("focusout",function() { | ||
| const value = emailInput.value.trim(); | ||
| if (value==""){ | ||
| emailError.textContent = "이메일을 입력해 주세요"; | ||
| emailError.style.display = "block"; | ||
| emailInput.classList.add("errorborder"); | ||
| error.email =0; | ||
| }else if(!emailPattern.test(value)){ | ||
| emailError.textContent = "잘못된 이메일 형식입니다."; | ||
| emailError.style.display = "block"; | ||
| emailInput.classList.add("errorborder"); | ||
| error.email =0; | ||
| }else{ | ||
| emailError.style.display="none" | ||
| emailInput.classList.remove("errorborder"); | ||
| error.email =1; | ||
| } | ||
| updateButtonState() | ||
| }) | ||
|
|
||
| nicknameInput.addEventListener("focusout",function(){ | ||
| const value = nicknameInput.value; | ||
| if(value == ""){ | ||
| nicknameError.textContent = "닉네임을 입력해 주세요"; | ||
| nicknameError.style.display = "block"; | ||
| nicknameInput.classList.add("errorborder"); | ||
| error.nickname =0; | ||
| }else{ | ||
| nicknameError.style.display = "none" | ||
| nicknameInput.classList.remove("errorborder"); | ||
| error.nickname =1; | ||
| } | ||
| updateButtonState() | ||
| }) | ||
|
|
||
| passwordInput.addEventListener("focusout", function(){ | ||
| const value = passwordInput.value; | ||
| if(value == ""){ | ||
| passwordError.textContent = "비밀번호를 입력해 주세요"; | ||
| passwordError.style.display = "block"; | ||
| passwordInput.classList.add("errorborder"); | ||
| error.password =0; | ||
| }else if(value.length<8){ | ||
| passwordError.textContent = "비밀번호를 8자 이상 입력해 주세요"; | ||
| passwordError.style.display = "block"; | ||
| passwordInput.classList.add("errorborder"); | ||
| error.password =0; | ||
| }else{ | ||
| passwordError.style.display="none" | ||
| passwordInput.classList.remove("errorborder"); | ||
| error.password =1; | ||
| } | ||
| updateButtonState() | ||
| }) | ||
|
|
||
| passwordcheckInput.addEventListener("focusout",function(){ | ||
| const value = passwordcheckInput.value; | ||
| const pw = passwordInput.value; | ||
| if(value.length<8){ | ||
| passwordcheckError.textContent = "비밀번호를 8자 이상 입력해 주세요"; | ||
| passwordcheckError.style.display = "block"; | ||
| passwordcheckInput.classList.add("errorborder"); | ||
| error.passwordcheck =0; | ||
| }else if(value != pw){ | ||
| passwordcheckError.textContent = "비밀번호가 일치하지 않습니다."; | ||
| passwordcheckError.style.display = "block"; | ||
| passwordcheckInput.classList.add("errorborder"); | ||
| error.passwordcheck =0; | ||
| }else{ | ||
| passwordcheckError.style.display="none" | ||
| passwordcheckInput.classList.remove("errorborder"); | ||
| error.passwordcheck =1; | ||
| } | ||
| updateButtonState() | ||
| }) | ||
|
|
||
| let showPw = false; | ||
| let showPc = false; | ||
|
|
||
| pwtoggle.addEventListener('click', function() { | ||
| showPw = !showPw; | ||
| passwordInput.type = showPw ? 'text' : 'password'; | ||
|
|
||
| pwon.style.display = showPw ? 'none' : 'inline'; | ||
| pwoff.style.display = showPw ? 'inline' : 'none'; | ||
| }); | ||
|
|
||
| pctoggle.addEventListener('click', function() { | ||
| showPc = !showPc; | ||
| passwordcheckInput.type = showPc ? 'text' : 'password'; | ||
|
|
||
| pcon.style.display = showPc ? 'none' : 'inline'; | ||
| pcoff.style.display = showPc ? 'inline' : 'none'; | ||
| }); | ||
|
|
||
| function updateButtonState(){ | ||
| const validcheck = error.email * error.password * error.nickname * error.passwordcheck; | ||
| if(validcheck ==1){ | ||
| button.disabled = false; | ||
| button.classList.remove("disabled"); | ||
| button.classList.add("enabled"); | ||
| }else { | ||
| button.disabled = true; | ||
| button.classList.add("disabled"); | ||
| button.classList.remove("enabled"); | ||
| } | ||
| } | ||
|
|
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.
혹시 아직 프리티어를 적용하지 않으셨나요 ?
사소한 줄바꿈, 띄어쓰기 등 코드를 작성하시다보면 자연스럽게 불규칙해지는 경우가 많아요.
이를 돕기 위해서 개발 커뮤니티에서는 개발 경험 향상을 위한 여러가지 도구들이 있는데요.
보편적으로 많이 사용되는 툴은
prettier입니다 !prettier는 vscode plugin에서install하고 실행할 수 있습니다 ! 🤗