JS隐藏部分手机号

WEB前端 90 2017-11-09 13:57

//用于隐藏部分手机号,银行卡号的javascript方法

replaceStr : function(str,keepLength,replaceChar,iskeeplast){

        iskeeplast = iskeeplast ? iskeeplast : true;

       keepLength = keepLength ? keepLength : 0;

       replaceChar = replaceChar ? replaceChar : '*';

       var sub = '';

       var length = str.length - keepLength;

       var replacement = '';

       if(iskeeplast){

           sub = str.substring(0, str.length - keepLength);

       } else {

           sub = str.substring(str.length - keepLength, str.length);

       }

       for(var i = 0; i < length; i++){

           replacement += replaceChar;

       };

       return str.replace(sub,replacement);

    }

文章评论