This article describes the method of using replace() to replace mobile phone number in JavaScript regular expression. Share it for your reference.
The specific implementation method is as follows:
The code copy is as follows:
<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.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 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>
I hope this article will be helpful to everyone's JavaScript programming.