Skip to content

Commit e0fb9fc

Browse files
authored
Merge pull request #325 from Nexters/develop
[운영배포] 전화번호 유형에 따른 길이 범위 반환 함수 추가 및 검증 로직 수정
2 parents 3963c89 + 0611e98 commit e0fb9fc

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

apps/admin/src/utils/phone.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ export function getMaxLengthByType(type: PhoneType): number {
5959
}
6060
}
6161

62+
export function getLengthRangeByType(type: PhoneType): { min: number; max: number } {
63+
switch (type) {
64+
case 'seoul':
65+
return { min: 9, max: 10 };
66+
case 'region':
67+
return { min: 10, max: 11 };
68+
case 'legacyMobile':
69+
return { min: 10, max: 11 };
70+
case 'mobile':
71+
case 'voip':
72+
return { min: 11, max: 11 };
73+
case 'special':
74+
return { min: 8, max: 8 };
75+
default:
76+
return { min: 11, max: 11 };
77+
}
78+
}
79+
6280
export function formatPhoneDynamic(input: string): {
6381
formatted: string;
6482
type: PhoneType;
@@ -107,7 +125,7 @@ export function formatPhoneDynamic(input: string): {
107125
export function validatePhoneOnBlur(input: string): boolean {
108126
const digits = stripNonDigits(input);
109127
const type = detectPhoneType(digits);
110-
const max = getMaxLengthByType(type);
111128
if (type === 'unknown') return false;
112-
return digits.length === max;
129+
const { min, max } = getLengthRangeByType(type);
130+
return digits.length >= min && digits.length <= max;
113131
}

0 commit comments

Comments
 (0)