Quantcast
Channel: masking of email address in java - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Answer by user1079877 for masking of email address in java

$
0
0

I like this one because I just want to hide 4 characters, it also dynamically decrease the hidden chars to 2 if the email address is too short:

public static String maskEmailAddress(final String email) {    final String mask = "*****";    final int at = email.indexOf("@");    if (at > 2) {        final int maskLen = Math.min(Math.max(at / 2, 2), 4);        final int start = (at - maskLen) / 2;        return email.substring(0, start) + mask.substring(0, maskLen) + email.substring(start + maskLen);    }    return email;}

Sample outputs:

my.email@gmail.com    >    my****il@gmail.cominfo@mail.com         >    i**o@mail.com

Viewing all articles
Browse latest Browse all 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>