JavaScript Regular Expressions Replace cell phone numbers with replace () _javascript tips

Source: Internet
Author: User

This example describes a JavaScript regular expression that replaces the phone number with replace (). Share to everyone for your reference.

The implementation methods are as follows:

Copy Code code as follows:

<title>javascript Regular expression replaces mobile phone number with replace () </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>
<body>
<p> your cell phone number is 13500112233<br/> Piggy's cell phone number is 13699887766 <br/> Bear's cell phone number is 13810102222</p>
<button> point I replace </button>
</body>

I hope this article will help you with your JavaScript programming.

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.