Showing
4 changed files
with
144 additions
and
16 deletions
This diff could not be displayed because it is too large.
1 | -import logo from './logo.svg'; | ||
2 | import './App.css'; | 1 | import './App.css'; |
2 | +import RegisterPage from './component/views/RegisterPage/RegisterPage'; | ||
3 | 3 | ||
4 | function App() { | 4 | function App() { |
5 | return ( | 5 | return ( |
6 | - <div className="App"> | 6 | + <div> |
7 | - <header className="App-header"> | 7 | + <RegisterPage /> |
8 | - <img src={logo} className="App-logo" alt="logo" /> | ||
9 | - <p> | ||
10 | - Edit <code>src/App.js</code> and save to reload. | ||
11 | - </p> | ||
12 | - <a | ||
13 | - className="App-link" | ||
14 | - href="https://reactjs.org" | ||
15 | - target="_blank" | ||
16 | - rel="noopener noreferrer" | ||
17 | - > | ||
18 | - Learn React | ||
19 | - </a> | ||
20 | - </header> | ||
21 | </div> | 8 | </div> |
22 | ); | 9 | ); |
23 | } | 10 | } | ... | ... |
1 | +import React, { useCallback, useState } from "react"; | ||
2 | + | ||
3 | +function RegisterPage(props) { | ||
4 | + | ||
5 | + const [Name, setName] = useState(""); | ||
6 | + const [Sex, setSex] = useState(""); | ||
7 | + const [Id, setId] = useState(""); | ||
8 | + const [Password, setPassword] = useState(""); | ||
9 | + const [PasswordCheck, setPasswordCheck] = useState(""); | ||
10 | + const [PasswordError, setPasswordError] = useState(false); | ||
11 | + | ||
12 | + const [checkNameError, setCheckNameError] = useState(false); | ||
13 | + const [checkSexError, setCheckSexError] = useState(false); | ||
14 | + const [checkIdError, setCheckIdError] = useState(false); | ||
15 | + const [checkPasswordError, setCheckPasswordError] = useState(false); | ||
16 | + const [checkRegisterError, setCheckRegisterError] = useState(false); | ||
17 | + | ||
18 | + const idRegex = /^(?=.*[a-zA-Z])(?=.*[0-9]).{6,14}$/; | ||
19 | + const passwordRegex = /^(?=.*[a-zA-Z])(?=.*[!@#$%^*+=-?])(?=.*[0-9]).{8,25}$/; | ||
20 | + | ||
21 | + const onIdHandler = useCallback((event) => { | ||
22 | + setId(event.currentTarget.value); | ||
23 | + | ||
24 | + // 아이디 유효성 검사 | ||
25 | + if (!idRegex.test(event.currentTarget.value)) { | ||
26 | + setCheckIdError(true); | ||
27 | + } | ||
28 | + else { | ||
29 | + setCheckIdError(false); | ||
30 | + } | ||
31 | + | ||
32 | + }, [checkIdError]); | ||
33 | + | ||
34 | + const onNameHandler = useCallback((event) => { | ||
35 | + setName(event.currentTarget.value); | ||
36 | + | ||
37 | + // 이름 유효성 검사 | ||
38 | + if (event.currentTarget.value.length < 2) { | ||
39 | + setCheckNameError(true); | ||
40 | + } | ||
41 | + else { | ||
42 | + setCheckNameError(false); | ||
43 | + } | ||
44 | + }, [checkNameError]); | ||
45 | + | ||
46 | + const onSexHandler = useCallback((event) => { | ||
47 | + setSex(event.currentTarget.value); | ||
48 | + }, [checkSexError]); | ||
49 | + | ||
50 | + const onPasswordHandler = useCallback((event) => { | ||
51 | + setPassword(event.currentTarget.value); | ||
52 | + | ||
53 | + // 비밀번호 유효성 검사 | ||
54 | + if (!passwordRegex.test(event.currentTarget.value)) { | ||
55 | + setCheckPasswordError(true); | ||
56 | + } | ||
57 | + else { | ||
58 | + setCheckPasswordError(false); | ||
59 | + } | ||
60 | + }, [checkPasswordError]); | ||
61 | + | ||
62 | + const onPasswordCheckHandler = useCallback((event) => { | ||
63 | + //비밀번호를 입력할때마다 password 를 검증하는 함수 | ||
64 | + setPasswordError(event.currentTarget.value !== Password); | ||
65 | + setPasswordCheck(event.currentTarget.value); | ||
66 | + },[PasswordError]); | ||
67 | + | ||
68 | + | ||
69 | + return ( | ||
70 | + <div id = "body"> | ||
71 | + <div className="register-box"> | ||
72 | + <h2>회원가입</h2> | ||
73 | + <div className="input-area"> | ||
74 | + <input | ||
75 | + placeholder="이름" | ||
76 | + type="text" | ||
77 | + value={Name} | ||
78 | + onChange={onNameHandler} | ||
79 | + /> | ||
80 | + </div> | ||
81 | + {checkNameError && <div style={{color : 'red'}}>이름을 두글자 이상 입력해 주세요.</div>} | ||
82 | + <div className="input-area"> | ||
83 | + <input | ||
84 | + placeholder="아이디" | ||
85 | + type="text" | ||
86 | + value={Id} | ||
87 | + onChange={onIdHandler} | ||
88 | + /> | ||
89 | + </div> | ||
90 | + {checkIdError && <div style={{color : 'red'}}>아이디는 6자리 이상 14자리 이하 알파벳 소문자와 숫자로 입력해주세요.</div>} | ||
91 | + <div className="input-area"> | ||
92 | + <input | ||
93 | + placeholder="비밀번호" | ||
94 | + type="text" | ||
95 | + value={Password} | ||
96 | + onChange={onPasswordHandler} | ||
97 | + /> | ||
98 | + </div> | ||
99 | + {checkPasswordError && <div style={{color : 'red'}}>알파벳과 숫자, 특수문자를 포함하여 8자리 이상 입력해주세요.</div>} | ||
100 | + <div className="input-area"> | ||
101 | + <input | ||
102 | + placeholder="비밀번호 재입력" | ||
103 | + type="text" | ||
104 | + value={PasswordCheck} | ||
105 | + onChange={onPasswordCheckHandler} | ||
106 | + /> | ||
107 | + </div> | ||
108 | + {PasswordError && <div style={{color : 'red'}}>비밀번호가 일치하지 않습니다.</div>} | ||
109 | + </div> | ||
110 | + <div className="input-area"> | ||
111 | + <input | ||
112 | + type="radio" | ||
113 | + value = "0" | ||
114 | + checked = {Sex === "0"} | ||
115 | + onChange={onSexHandler} | ||
116 | + />남 | ||
117 | + <input | ||
118 | + type="radio" | ||
119 | + value = "1" | ||
120 | + checked = {Sex === "1"} | ||
121 | + onChange={onSexHandler} | ||
122 | + />여 | ||
123 | + </div> | ||
124 | + <div className="btn-area"> | ||
125 | + <button | ||
126 | + className="register-btn" | ||
127 | + content="Sign up"> | ||
128 | + 회원가입 | ||
129 | + </button> | ||
130 | + </div> | ||
131 | + </div> | ||
132 | + ); | ||
133 | + | ||
134 | +} | ||
135 | + | ||
136 | +export default RegisterPage; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment