-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 웹팩 설정 변경 - 구조 정리 - 번들 파일을 3개로(로그인, 회원가입, 메인) 분리. 웹팩 이해 부족으로 제대로 작동하지 않았음 - 유효성 검증 코드 작성 중
- Loading branch information
1 parent
2978b97
commit fdb8bac
Showing
16 changed files
with
173 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
import "../scss/home.scss"; | ||
import "./scss/home.scss"; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
export const PATTERN = { | ||
userId: "^[a-z0-9-_]{5,20}$", | ||
password: "^(?=.*[A-Za-z])(?=.*d)(?=.*[!@#$%^&*_+~])[A-Za-zd!@#$%^&*_+~]{8,16}$", | ||
email: "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$", | ||
phoneNumber: "^(010)(d{7,8})$", | ||
year: "^(0-9)$", | ||
}; | ||
|
||
export const LIMITED_LENGTH = { | ||
userId: 20, | ||
password: 16, | ||
year: 4, | ||
}; | ||
|
||
export const FORM_ID = { | ||
userId: "#userId", | ||
password: "#password", | ||
checkPassword: "#check-password", | ||
email: "#email", | ||
phoneNumber: "#phoneNumber", | ||
name: "#name", | ||
year: "#year", | ||
month: "#month", | ||
day: "#day", | ||
gender: "#gender", | ||
interest: "#interest", | ||
}; | ||
|
||
export const ERROR_MSG_ID = { | ||
userId: "#error-msg-id", | ||
password: "#error-msg-password", | ||
checkPassword: "#error-msg-check-password", | ||
email: "#error-msg-email", | ||
phoneNumber: "#error-msg-phoneNumber", | ||
birthday: "#error-msg-birthday", | ||
interest: "#error-msg-interest", | ||
}; | ||
|
||
export const TOGGLE_CLASS = { | ||
pass: "pass", | ||
error: "error", | ||
focus: "forus", | ||
hidden: "hidden", | ||
disabled: "disabled", | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const _q = str => { | ||
return document.querySelector(str); | ||
}; | ||
|
||
export const _qa = str => { | ||
return document.querySelectorAll(str); | ||
}; | ||
|
||
export const pipe = (...fns) => value => fns.reduce((acc, fn) => fn(acc), value); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { _q, _qa, pipe } from "./util.js"; | ||
import { PATTERN, FORM_ID, ERROR_MSG_ID, TOGGLE_CLASS } from "./constants.js"; | ||
|
||
const isInputTag = elem => { | ||
return !!(elem.tagName === "INPUT" || elem.tagName === "SELECT"); | ||
}; | ||
|
||
const setInputPattern = (target, regExp) => { | ||
if (!isInputTag(target)) return; | ||
target.pattern = regExp; | ||
}; | ||
|
||
const fields = { | ||
userId: { | ||
isFieldValid() { | ||
const userId = _q(FORM_ID.userId); | ||
const { value } = userId; | ||
const isValid = userId.validity.valid; | ||
return value !== "" && isValid; | ||
}, | ||
errorMessage: { | ||
misMatch: "5~20자의 영문 소문자, 숫자와 특수기호(_)(-) 만 사용 가능합니다.", | ||
overlap: "이미 사용중인 아이디입니다.", | ||
}, | ||
errorMessageElement: _q(ERROR_MSG_ID.userId), | ||
passMessage: "사용 가능한 아이디입니다.", | ||
}, | ||
|
||
password: { | ||
isFieldValid() { | ||
const password = _q(FORM_ID.password); | ||
const { value } = password; | ||
return value !== ""; | ||
}, | ||
errorMessage: { | ||
range: "8자 이상 16자 이하로 입력해주세요.", | ||
upperCase: "영문 대문자를 최소 1자 이상 포함해주세요.", | ||
number: "숫자를 최소 1자 이상 포함해주세요.", | ||
sign: "특수문자를 최소 1자 이상 포함해주세요.", | ||
}, | ||
errorMessageElement: _q(ERROR_MSG_ID.password), | ||
passMessage: "안전한 비밀번호입니다.", | ||
}, | ||
|
||
checkPassword: { | ||
isFieldValid() { | ||
const password = _q(FORM_ID.password).value; | ||
return password !== ""; | ||
}, | ||
errorMessageElement: _q(ERROR_MSG_ID.checkPassword), | ||
errorMessage: "비밀번호가 일치하지 않습니다.", | ||
passMessage: "비밀번호가 일치합니다.", | ||
}, | ||
}; | ||
|
||
const init = () => { | ||
const userIdInput = _q(FORM_ID.userId); | ||
const passwordInput = _q(FORM_ID.password); | ||
const checkPasswordInput = _q(FORM_ID.checkPassword); | ||
const emailInput = _q(FORM_ID.email); | ||
const phoneNumberInput = _q(FORM_ID.phoneNumber); | ||
|
||
setInputPattern(userIdInput, PATTERN.userId); | ||
setInputPattern(passwordInput, PATTERN.password); | ||
setInputPattern(checkPasswordInput, PATTERN.password); | ||
setInputPattern(emailInput, PATTERN.email); | ||
setInputPattern(phoneNumberInput, PATTERN.phoneNumber); | ||
}; | ||
|
||
init(); | ||
|
||
_q("form").addEventListener("input", e => { | ||
const tagName = e.target.name; | ||
let message = ""; | ||
console.log(fields.userId.isFieldValid()); | ||
switch (tagName) { | ||
case "userId": | ||
if (e.target.value === "") { | ||
return; | ||
} | ||
if (!e.target.validity.valid) { | ||
message = "5~20자의 영문 소문자, 숫자와 특수기호(_)(-) 만 사용 가능합니다."; | ||
_q(ERROR_MSG_ID.userId).innerHTML = message; | ||
_q(ERROR_MSG_ID.userId).classList.add(TOGGLE_CLASS.error); | ||
_q(ERROR_MSG_ID.userId).classList.remove(TOGGLE_CLASS.pass); | ||
} else { | ||
message = "사용 가능한 아이디입니다."; | ||
_q(ERROR_MSG_ID.userId).innerHTML = message; | ||
_q(ERROR_MSG_ID.userId).classList.remove(TOGGLE_CLASS.error); | ||
_q(ERROR_MSG_ID.userId).classList.add(TOGGLE_CLASS.pass); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
}); | ||
|
||
_q(".btn-wrap").addEventListener("click", e => { | ||
e.preventDefault(); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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 |
---|---|---|
|
@@ -9,8 +9,6 @@ | |
top: 0; | ||
left: 0; | ||
z-index: 1; | ||
opacity: 1; | ||
transition: opacity 0.2s ease; | ||
} | ||
|
||
.modal { | ||
|
File renamed without changes.
File renamed without changes.
This file contains 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 |
---|---|---|
|
@@ -11,8 +11,7 @@ | |
} | ||
|
||
.hidden { | ||
visibility: hidden; | ||
opacity: 0; | ||
display: none; | ||
} | ||
|
||
.disabled { | ||
|
File renamed without changes.
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
import "../scss/signin.scss"; | ||
import "./scss/signin.scss"; |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
import "../scss/main.scss"; | ||
import "./scss/main.scss"; | ||
import "./modules/validation"; |
This file contains 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