전화번호나 핸드폰 번호를 db에 삽입할때 숫자만 넣는 경우도 있다.

 

그 데이터를 다시 불러올때 번호 같은 것은 자릿수 대로 나눠줘야 할 필요가 있다.

 

 

/**
 * 번호 분류별로 구분
 * @num '-' 문자가 들어있지않은 숫자로된 전화번호
 */
function phoneFomatter(num,type){
    var formatNum = '';
    if(num.length==11){
         formatNum = num.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3');
    }else if(num.length==8){
        formatNum = num.replace(/(\d{4})(\d{4})/, '$1-$2');
    }else{
        if(num.indexOf('02')==0){
            formatNum = num.replace(/(\d{2})(\d{4})(\d{4})/, '$1-$2-$3');
        }else{
            formatNum = num.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
        }
    }
	}
    return formatNum;
}

+ Recent posts