There are several methods for front-end js to desensitize mobile phone numbers

// There are several ways to desensitize the mobile phone number
// Method 1: Use the substring() method
let mobilePhone1="19909091221";
let desensitization=mobilePhone1.substring(0,3)+" **** "+mobilePhone1.substring( 7);
// Method 2: Use substring() method
let mobilePhone2="19909091221";
let desensitization2=mobilePhone2.substr(0,3)+" **** "+mobilePhone2.substring(7);
// Method 3 : Use regular expression method
let mobilePhone3="19909091221";
let regular=/(\d{3})\d*(\d{4})/
let desensitization3=mobilePhone3.replace(regular,'$1**** $2');

          //总结一下区别:
          //  substring第一个参数是开始下标,第二个是结束下标。
          //  substr第一个参数是开始下标,第二个是截取几位。

Guess you like

Origin blog.csdn.net/m0_46577631/article/details/128344356