Skip to content

Commit e116a15

Browse files
authored
Merge pull request #421 from Podo-Store/fix/payment-phone-format
fix: 결제 진행 시 신청자 전화번호 형식 검증 추가 및 하이픈 자동 추가
2 parents 3513a05 + 75d775f commit e116a15

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/pages/payment/Purchase.jsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,17 @@ const Purchase = () => {
9595
}
9696
}, [name]);
9797

98+
// useEffect(() => {
99+
// if (phone.length > 0 && phone.trim() !== "") {
100+
// setPhoneValid(true);
101+
// } else {
102+
// setPhoneValid(false);
103+
// }
104+
// }, [phone]);
105+
98106
useEffect(() => {
99-
if (phone.length > 0 && phone.trim() !== "") {
100-
setPhoneValid(true);
101-
} else {
102-
setPhoneValid(false);
103-
}
107+
const PHONE_REGEX = /^010-\d{4}-\d{4}$/;
108+
setPhoneValid(PHONE_REGEX.test(phone));
104109
}, [phone]);
105110

106111
useEffect(() => {
@@ -183,8 +188,14 @@ const Purchase = () => {
183188
setIsLoading(true);
184189

185190
// 1) 사용자 입력 검증
186-
if (buyPerform && (!nameValid || !phoneValid || !addressValid)) {
187-
alert("신청자 정보를 다시 확인해주세요.");
191+
// if (buyPerform && (!nameValid || !addressValid)) {
192+
// alert("신청자 정보를 다시 확인해주세요.");
193+
// setIsLoading(false);
194+
// return;
195+
// }
196+
197+
if (buyPerform && !phoneValid) {
198+
alert("전화번호 입력 형식을 다시 확인해 주세요 (010-****-****)");
188199
setIsLoading(false);
189200
return;
190201
}
@@ -268,7 +279,6 @@ const Purchase = () => {
268279
JSON.stringify(requestBody)
269280
);
270281

271-
272282
requestPay({
273283
clientId: import.meta.env.VITE_NICEPAY_CLIENT_KEY,
274284
method: nicepayMethod, // 'card' | 'bank' | 'vbank'

0 commit comments

Comments
 (0)