Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate different phone number formats #38993

Merged
merged 14 commits into from
Apr 3, 2024
Merged
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"date-fns-tz": "^2.0.0",
"dom-serializer": "^0.2.2",
"domhandler": "^4.3.0",
"expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#4e020cfa13ffabde14313c92b341285aeb919f29",
"expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#aa2c6d204228870feb6e9b402030e3e97ece3714",
"expo": "^50.0.3",
"expo-av": "~13.10.4",
"expo-image": "1.11.0",
Expand Down
2 changes: 2 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,8 @@ const CONST = {
POLICY_ID_FROM_PATH: /\/w\/([a-zA-Z0-9]+)(\/|$)/,

SHORT_MENTION: new RegExp(`@[\\w\\-\\+\\'#@]+(?:\\.[\\w\\-\\'\\+]+)*`, 'gim'),

PHONE_NUMBER: /(\+\d{1,2}\s?)?(\(\d{3}\)|\d{3})[\s.-]?\d{3}[\s.-]?\d{4}/,
tienifr marked this conversation as resolved.
Show resolved Hide resolved
},

PRONOUNS: {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/LoginUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function isEmailPublicDomain(email: string): boolean {
function validateNumber(values: string): string {
const parsedPhoneNumber = parsePhoneNumber(values);

if (parsedPhoneNumber.possible && Str.isValidPhone(values.slice(0))) {
if (parsedPhoneNumber.possible && Str.isValidE164Phone(values.slice(0))) {
return `${parsedPhoneNumber.number?.e164}${CONST.SMS.DOMAIN}`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ function getOptions(
!isCurrentUser({login: searchValue} as PersonalDetails) &&
selectedOptions.every((option) => 'login' in option && option.login !== searchValue) &&
((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue) && !Str.endsWith(searchValue, CONST.SMS.DOMAIN)) ||
(parsedPhoneNumber.possible && Str.isValidPhone(LoginUtils.getPhoneNumberWithoutSpecialChars(parsedPhoneNumber.number?.input ?? '')))) &&
(parsedPhoneNumber.possible && Str.isValidE164Phone(LoginUtils.getPhoneNumberWithoutSpecialChars(parsedPhoneNumber.number?.input ?? '')))) &&
!optionsToExclude.find((optionToExclude) => 'login' in optionToExclude && optionToExclude.login === PhoneNumber.addSMSDomainIfPhoneNumber(searchValue).toLowerCase()) &&
(searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas)) &&
!excludeUnknownUsers
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,7 @@ function getParsedComment(text: string): string {
return `@${mentionWithEmailDomain}`;
}
}
if (Str.isValidPhone(mention)) {
if (Str.isValidE164Phone(mention)) {
const mentionWithSmsDomain = PhoneNumber.addSMSDomainIfPhoneNumber(mention);
if (allPersonalDetailLogins.includes(mentionWithSmsDomain)) {
return `@${mentionWithSmsDomain}`;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/UserUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function getSmallSizeAvatar(avatarSource: AvatarSource, accountID?: number): Ava
*/
function getSecondaryPhoneLogin(loginList: OnyxEntry<Login>): string | undefined {
const parsedLoginList = Object.keys(loginList ?? {}).map((login) => Str.removeSMSDomain(login));
return parsedLoginList.find((login) => Str.isValidPhone(login));
return parsedLoginList.find((login) => Str.isValidE164Phone(login));
}

export {
Expand Down
Loading