Mask Mobile Number

In this example below you will see how to do a Mask Mobile Number with some HTML / CSS and Javascript

Here we write logic for masking of mobile number. Here in this code we write last 4 numbers as it is and rest of things will replace with X.

Thumbnail
This awesome code was written by yogeshjadhav, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright yogeshjadhav ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Mask Mobile Number</title>
  
  
  
  
  
</head>

<body>

  
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/yogeshjadhav/mask-mobile-number-mMwNyg */
var str = "12345678901"; 
var mobNum = str.slice(-4);
var restMobNum = str.substring(0, str.length - 7).replace(/\d/g, 'X'); 
console.log("Original Number: "+str);
console.log("Masked Number: "+restMobNum+ " XXX " +mobNum);
console.log("Masked Logic last 4 numbers will display as it is rest will convert into X.");

Comments