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 ""}