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.