JavaScript verifies mobile number and implements asterisk (*) instead of instance _javascript tips

Source: Internet
Author: User

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

<!doctype html>
 
 

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

<!doctype html>
 
 

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

<!doctype html>  

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.