Quantcast
Viewing all articles
Browse latest Browse all 9

Answer by MarGin for masking of email address in java

Kotlin Extension

/** * Format email id in the following format * (m••••••n@gmail.com) * only exception for 2 character username in that case it will be ••@gmail.com * @return formatted email */fun String.maskEmailId(): String {    return if (this.isNotNullOrEmpty() && this.indexOf('@') > 0) {        val index = this.indexOf('@')        val maskedUsername = if (index > 2) {"${this.substring(0, 1)}${"*".repeat(index-2)}${this.substring(index-1)}"        } else {"*".repeat(index) + this.substring(index)        }        maskedUsername    }  else ""}

Viewing all articles
Browse latest Browse all 9

Trending Articles