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.