手机号码格式转化为 344 格式

export function phoneFormat(phoneNumber) {
  if (!phoneNumber) {
    return null;
  }
  let tel = phoneNumber.replace(/(^\s+)|(\s+$)/g, '');
  tel = tel.replace(/\s/g, '');
  if (!tel) {
    return null;
  }

  if (tel.length === 11) {
    tel = tel.substring(0, 3) + '-' + tel.substring(3, 7) + '-' + tel.substring(7, 11);
  } else if (tel.length === 12) {
    tel = tel.substring(0, 4) + ' ' + tel.substring(4, 8) + '-' + tel.substring(8, 12);
  }
  return tel;
}

 

posted @ 2020-11-26 18:48  无人问及  阅读(505)  评论(0编辑  收藏  举报