Masking Personal Information
specialist · 865 · lc medium +31 · verified · 54.2% accepted · 200 likes · top 46%
Description
Given a personal information string s that is either an email address or a phone number, return the masked version according to the following rules.
Email address:
An email address has:
- A name (uppercase and lowercase letters), followed by
- The '@' symbol, followed by
- A domain (letters with a '.' somewhere in the middle, not at the first or last position).
To mask an email:
- Convert all letters in the name and domain to lowercase.
- Replace every letter in the name except the first and last with five asterisks "*****".
Phone number:
A phone number contains 10-13 digits. The last 10 digits form the local number; any leading 0-3 digits form the country code. Separation characters {'+', '-', '(', ')', ' '} may appear.
To mask a phone number:
- Strip all separation characters.
- Format the result as:
- "***-***-XXXX" if there is no country code.
- "+*-***-***-XXXX" for a 1-digit country code.
- "+**-***-***-XXXX" for a 2-digit country code.
- "+***-***-***-XXXX" for a 3-digit country code.
- "XXXX" represents the last 4 digits of the local number.
Example 1:
Example 2:
Example 3:
Code