Skip to content

Commit 8a3292e

Browse files
authored
[EC-45] feat: 개인정보 수정 유효성 검사 (#60)
1 parent 403a922 commit 8a3292e

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

client/src/pages/studentSetting/StudentSetting.jsx

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import styles from './StudentSetting.module.css';
33
import InputBox from '../../components/inputBox/InputBox';
44
import MainButton from '../../components/buttons/mainButton/MainButton';
55

66
export default function StudentSetting() {
7-
const handleChange = () => {};
7+
const [error, setError] = useState('');
8+
const [input, setInput] = useState({
9+
phoneNumber: '',
10+
password: '',
11+
});
12+
13+
const validatePhoneNumber = (phoneNumber) => {
14+
const phoneRegex = /^[0-9]{3}-[0-9]{3,4}-[0-9]{4}$/;
15+
return phoneRegex.test(phoneNumber);
16+
};
17+
18+
const validatePassword = (password) => {
19+
const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,16}$/;
20+
return passwordRegex.test(password);
21+
};
22+
23+
const handleSubmit = (e) => {
24+
e.preventDefault();
25+
};
26+
27+
useEffect(() => {
28+
if (!validatePhoneNumber(input.phoneNumber)) {
29+
setError('연락처를 다시 입력해주세요.');
30+
} else if (!validatePassword(input.password)) {
31+
setError('비밀번호는 8자 이상, 대소문자, 숫자, 특수문자를 포함해야 합니다.');
32+
} else {
33+
setError('');
34+
alert('개인정보가 수정 되었습니다.');
35+
}
36+
}, [input.phoneNumber, input.password]);
37+
38+
const handleChange = (e) => {
39+
const { name, value } = e.target;
40+
setInput((preInput) => ({
41+
...preInput,
42+
[name]: value,
43+
}));
44+
};
845

946
return (
10-
<form className={styles.studentSetting}>
47+
<form className={styles.studentSetting} onSubmit={handleSubmit}>
1148
<InputBox
1249
type="text"
1350
title="연락처"
@@ -27,19 +64,9 @@ export default function StudentSetting() {
2764
isSelect="(선택)"
2865
></InputBox>
2966

30-
<InputBox
31-
type="text"
32-
title="월"
33-
disabled={false}
34-
onChange={handleChange}
35-
></InputBox>
67+
<InputBox type="text" title="월" disabled={false} onChange={handleChange}></InputBox>
3668

37-
<InputBox
38-
type="text"
39-
title="일"
40-
disabled={false}
41-
onChange={handleChange}
42-
></InputBox>
69+
<InputBox type="text" title="일" disabled={false} onChange={handleChange}></InputBox>
4370
</div>
4471

4572
<InputBox
@@ -73,6 +100,8 @@ export default function StudentSetting() {
73100
content="현재 비밀번호는 필수 입력값입니다."
74101
></InputBox>
75102

103+
{error && <div style={{ color: 'red' }}></div>}
104+
76105
<MainButton title="수정"></MainButton>
77106
</form>
78107
);

0 commit comments

Comments
 (0)