How to hide phone number by masking it?

Dondon510 261 Reputation points
2022-07-10T00:59:42.423+00:00

I'm trying to hide phone no by masking it, I found this but it doesn't really fulfill the need.

Question:

if I have phone no 0123456789, how to mask to 0XXXXXXXX9?

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

Accepted answer
  1. satya karki 996 Reputation points MVP
    2022-07-10T02:29:55.757+00:00

    HI @Dondon510 ,

    You can try this simple way.

    str.substring(0, 5) +  
                    str.substring(5, str.length() - 3)  
                    .replaceAll("[\\d]", "x") +  
                    str.substring(str.length() - 3, str.length());  
    

    https://stackoverflow.com/questions/31000039/mask-all-digits-except-first-6-and-last-4-digits-of-a-string-length-varies

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.