Last active
November 19, 2021 00:11
-
-
Save tanpld/eb9a25f399260b1cf814edc48926745a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const maskedFirst4Char = (value: string): string => { | |
return value.replace(/.(?=.{4})/g, '*'); | |
} | |
const maskPhoneNumber = (phone: string): string => { | |
if (!phone) return 'N/A'; | |
const code = phone.slice(0, 2); | |
const number = phone.slice(2); | |
const maskedFirst4Number = maskedFirst4Char(number) | |
.replace(/.(?=(.{4})+$)/g, '$& '); // add a space after every 4 number | |
return `+${code} ${maskedFirst4Number}`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment