diff --git a/apps/dm/app/store/sdmMng/index.tsx b/apps/dm/app/store/sdmMng/index.tsx index 0041f5a93..2627909b6 100644 --- a/apps/dm/app/store/sdmMng/index.tsx +++ b/apps/dm/app/store/sdmMng/index.tsx @@ -43,6 +43,34 @@ export const sdmInfoFormSchema = z.object({ export type SdmInfoFormData = z.infer; +const formatTelno = (telno?: string | null) => { + const digits = (telno ?? '').replace(/\D/g, ''); + + if (!digits) { + return ''; + } + + if (digits.startsWith('02')) { + if (digits.length === 9) { + return digits.replace(/(02)(\d{3})(\d{4})/, '$1-$2-$3'); + } + + if (digits.length === 10) { + return digits.replace(/(02)(\d{4})(\d{4})/, '$1-$2-$3'); + } + } + + if (digits.length === 10) { + return digits.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3'); + } + + if (digits.length === 11) { + return digits.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3'); + } + + return telno ?? ''; +}; + // 수요처 정보 export type DemandCompBizType = { @@ -694,7 +722,7 @@ export const SdmReducer = (set: any): SdmActions => { dmdInfoId: res.dmdInfoId, zip: res.zip || '', daddr: res.daddr, - telno: res.telno.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3'), + telno: formatTelno(res.telno), rgtr: res.rgtr, ctpvCd: res.ctpvCd, sggCd: res.sggCd,