SoFunction
Updated on 2025-03-01

Method of replacing mobile phone number with replace in javascript regular expression


<html>
<head>
<title>javascript regular expression uses replace() to replace mobile phone number</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript" src="jquery-1.8."></script>
<script type="text/javascript">
 $(function(){
  $("button").click(function(){
   var str = $("p").text();
   var reg = /1(\d{2})\d{4}(\d{4})/g;
   str = (reg,"1$1****$2");
   $("p").text(str);
  });
 });
</script>
<style type="text/css">
h5{color:blue;}
</style>
</head>
<body>
<h5>Replace the 4th to 7th position of the mobile phone number with ****</h5>
<p>Your mobile phone number is 13500112233<br />Xiaozhu's mobile phone number is 13699887766 <br /> Big Bear's mobile phone number is 13810102222</p>
<button>Click me to replace</button>
</body>
</html>