function phoneFomatter(num,type){
var formatNum = '';
if(num.length==11){
if(type==0){
formatNum = num.replace(/(\d{3})(\d{4})(\d{4})/, '$1-****-$3');
}else{
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){
if(type==0){
formatNum = num.replace(/(\d{2})(\d{4})(\d{4})/, '$1-****-$3');
}else{
formatNum = num.replace(/(\d{2})(\d{4})(\d{4})/, '$1-$2-$3');
}
}else{
if(type==0){
formatNum = num.replace(/(\d{3})(\d{3})(\d{4})/, '$1-***-$3');
}else{
formatNum = num.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
}
}
}
return formatNum;
}
Created
July 7, 2022 08:30
-
-
Save sbin0819/b9700428c2fb87146be72359560b4463 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment