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
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 @@ -1695,7 +1695,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 @@ -3044,7 +3044,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
2 changes: 1 addition & 1 deletion src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ function isValidUSPhone(phoneNumber = '', isCountryCodeOptional?: boolean): bool

// When we pass regionCode as an option to parsePhoneNumber it wrongly assumes inputs like '=15123456789' as valid
// so we need to check if it is a valid phone.
if (regionCode && !Str.isValidPhone(phone)) {
if (regionCode && !Str.isValidPhoneFormat(phone)) {
return false;
}

Expand Down
Loading