首页 > 移动平台 > 详细

隐藏手机号

时间:2020-02-09 15:32:01      阅读:66      评论:0      收藏:0      [点我收藏+]
/**
 * 隐藏手机号码
 * @param phone 手机号码
 * @param startIndex 从第几个数字开始隐藏
 * @param endIndex 隐藏至第几个数字
 */
function hiddenPhone(phone, startIndex = 4, endIndex = 7) {
  if (typeof phone !== string) {
    return ‘‘;
  }
  const maxLength = 11;
  const fontLength = startIndex - 1;
  const endLength = maxLength - endIndex;
  const hiddenLength = maxLength - fontLength - endLength;
  const reg = new RegExp(`(\\d{${fontLength}})(\\d{${hiddenLength}})(\\d{${endLength}})`);
  let star = ‘‘;
  len = endIndex-startIndex +1;
  for(let i = 0;i< len;i++) {
    star += *
  }
  return phone.replace(reg, `$1${star}$3`);
}

默认隐藏第4-7位的数字

技术分享图片

 

 

 

 

 



隐藏手机号

原文:https://www.cnblogs.com/ympjsc/p/12287190.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!