One, the JavaScript replaces mobile phone number middle 4 digits
Match the handset number to the end, in the form of a similar "123****8901" Output
' 12345678901 '. Replace (/(\d{3}) \d{4} (\d{4})/, ' $1****$2 ');
Example
Note: This section is matched by a sequential 11-digit number in the string, replacing the middle 4-digit with the * number, and outputting the usual hidden phone number format. If you want to get only the end 4 digits, you can change to the following form:
Second, JavaScript replacement mobile phone number of the first 7 digits
Match 11 digits in a row and replace the first 7 digits with the * number
' 15110280327 '. Replace (/\d{7} (\d{4})/, ' *******$1 ');
Example
Supplemental Comments: parentheses in regular expressions can be used for grouping and also for defining child-mode strings, and in the Replace () method, $n (n is a number) is used in parameter two to refer to a string of parentheses defined in the pattern string.
Third, JavaScript mobile phone verification and hidden mobile phone number of the middle four-bit comprehensive example
Summarize
The above is JavaScript to verify the phone number and implementation of the asterisk (*) Replace the full content of the effect, I hope this article will help you to use JavaScript everyday.