zoukankan      html  css  js  c++  java
  • js中让字符串中特定字符(数字标识)*显示 名字中间用*代替,电话中间加密,详细地址数字使用*

           //隐藏名字
        formatName = (name)=>{
            let newStr = '';
            if(name.length === 2){
                newStr = name.substr(0,1)+'*';
            }else if(name.length>2){
               let char = '';
               for(let i=0,len = name.length-2;i<len;i++){
                     char += '*';
               }
               newStr = name.substr(0,1)+char+name.substr(-1,1);
            }else{
                newStr = name
            }
              return newStr;
        }
        //隐藏电话
        formatTel = (tel)=>{
            tel = "" + tel;
            let newTel = tel.substr(0,3) + "****" + tel.substr(7)
            return newTel;
        }
        formatAddressX=(addr)=>{
            var nums = String(addr.match(/d+(.d+)?(%)?(‰)?/g));
            var numArray = nums.split(',');
            var compare = function (x, y) {
                if (parseFloat(x) < parseFloat(y)) {
                    return 1;
                } else if (parseFloat(x) > parseFloat(y)) {
                    return -1;
                } else {
                    return 0;
                }
            }
            //按数组的大小降序排列,很大程度上减少执行以下全局replace而带来的匹配不了问题
            numArray.sort(compare)
            for(var i=0; i<numArray.length;i++){
                var pattern = new RegExp(numArray[i],"gm");
                addr = addr.replace(pattern,"*");
            }
            return addr;
        }
  • 相关阅读:
    HDFS API
    Wrong FS: hdfs://xxx/xxx expected: file:///
    Sqoop拒绝连接错误
    MySQL设置远程连接
    Eclipse远程连接Hadoop
    Hadoop创建新用户
    Nutch的安装和配置
    NameNode重新格式化以后DataNode不能启动
    Pig拒绝连接错误
    Pig jline.Terminal错误
  • 原文地址:https://www.cnblogs.com/isuansuan/p/13631149.html
Copyright © 2011-2022 走看看