You can try the following:
var contactNumber = "9087654321";
var maskedNumber = contactNumber.substr(0, 3) + Array(contactNumber.length - 4).join('*') + contactNumber.substr(contactNumber.length - 2, 2);
It takes the first 3 and last 2 numbers and fills the gap with asterisks (asterisk).
Result maskedNumberwill be908*****21
For security reasons, I would recommend PatNowak's answer as it hides the contact number until it is sent to the client.
source
share