The regular expression replace () is used to replace the mobile phone number.

Source: Internet
Author: User

The regular expression replace () is used to replace the mobile phone number.

This example describes how to replace a mobile phone number with a regular expression in javascript. Share it with you for your reference.

The specific implementation method is as follows:

Copy codeThe Code is as follows:
<Html>
<Head>
<Title> replace () with the mobile phone number in a javascript Regular Expression </title>
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8"/>
<Script type = "text/javascript" src = "jquery-1.8.2.min.js"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("Button"). click (function (){
Var str = $ ("p"). text ();
Var reg =/1 (\ d {2}) \ d {4} (\ d {4})/g;
Str = str. replace (reg, "1 $1 ***** $2 ");
$ ("P"). text (str );
});
});
</Script>
<Style type = "text/css">
H5 {color: blue ;}
</Style>
</Head>
<Body>
<H5> Replace the 4th-to-7th-bit mobile phone number with ***** <P> your mobile phone number is 13500112233 <br/> the mobile phone number of pig is 13699887766 <br/> the mobile phone number of bear is 13810102222 </p>
<Button> click "replace" </button>
</Body>
</Html>

I hope this article will help you design javascript programs.

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.