260716_02_ENH: 프로젝트에 발신 번호추가 및 리다이렉트 url, api 수정
This commit is contained in:
22
src/utils/phone.ts
Normal file
22
src/utils/phone.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// 특수/대표번호(15XX, 16XX, 18XX 등): 지역번호 없이 4자리-4자리
|
||||
const SPECIAL_NUMBER_PREFIX = /^(15|16|18)\d{2}/;
|
||||
|
||||
export const formatKoreanPhoneNumber = (value: string): string => {
|
||||
const digits = value.replace(/\D/g, "");
|
||||
|
||||
if (SPECIAL_NUMBER_PREFIX.test(digits) && digits.length === 8) {
|
||||
return `${digits.slice(0, 4)}-${digits.slice(4)}`;
|
||||
}
|
||||
|
||||
if (digits.startsWith("02")) {
|
||||
if (digits.length === 9) return `${digits.slice(0, 2)}-${digits.slice(2, 5)}-${digits.slice(5)}`;
|
||||
if (digits.length === 10) return `${digits.slice(0, 2)}-${digits.slice(2, 6)}-${digits.slice(6)}`;
|
||||
return value;
|
||||
}
|
||||
|
||||
// 010/011~019(휴대폰), 070(인터넷전화), 031~064(지역번호) 등 3자리 국번
|
||||
if (digits.length === 10) return `${digits.slice(0, 3)}-${digits.slice(3, 6)}-${digits.slice(6)}`;
|
||||
if (digits.length === 11) return `${digits.slice(0, 3)}-${digits.slice(3, 7)}-${digits.slice(7)}`;
|
||||
|
||||
return value;
|
||||
};
|
||||
Reference in New Issue
Block a user