1
2
3
4
5
var phoneNum = "010333-5555";
phoneNum = $.trim(phoneNum); // 앞뒤 공백제거
phoneNum = phoneNum.replace(/-/gi, ""); // - 하이픈 제거
phoneNum = phoneNum.replace(/^(\d{2,3})(\d{3,4})(\d{4})$/"$1-$2-$3");
console.log(phoneNum); // 010-333-5555

 

반응형
Posted by 힘없는염소