PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 23, 2022

[FIXED] how to mask email and phone number with regular expression with fixed length substitution

 October 23, 2022     .net, c#, email, regex, substitution     No comments   

Issue

I am writing regEx for masking Email address and Phone number in Azure B2C Claims

My requirement is as follows,

For Email address, I need to display first two characters of the email unmasked and fixed 5 * (masked) irrespective of length remaining characters and unmasked "@domain.com" Expected Result (for example):

testaccount@gmail.com ==> te*****@gmail.com

test@gmail.com ==>te*****@gmail.com

My regular expression is currently display first two characters and replacing remaining characters with *

RegEx: https://regex101.com/r/3xL2ht/1

For Mobile:

I need to display seven asterisk as masked characters irrespective of number digits. last 4 digits should be unmasked.

Expected Result (for example):

+91-1234567890 ==> *******7890

919012345678 ==> *******5678

Current configuration is showing last 4 digits correctly, but preceding digits are replaced by * , if I have 12 digit, it shows eight asterisk and las 4 digit.

Current regEx : https://regex101.com/r/56DpA6/1

Please help me in sorting this out!

Thank you!!


Solution

For your mail problem:

replace ([^@]{1,2})[^@]*(.+) with $1.....$2

  • search for the two first letters (not '@') and capture them
  • search for the rest in front of '@' (and forget it)
  • capture the rest (beginning at '@')

[EDIT] I think your other question can be solved very similar. Capture the last digits and concat them to your new (asterisk) string.



Answered By - Klamsi
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing