Skip to content

Commit 35415b1

Browse files
Accept US territory phone numbers in isValidUSPhone validation
The isValidUSPhone function previously required region code to be exactly 'US', which rejected valid phone numbers from US territories that share the +1 country code but have their own ISO region codes (e.g., PR for Puerto Rico, GU for Guam). This caused users in Puerto Rico to see "Please enter a complete phone number" errors when trying to add their phone for bank account verification. Co-authored-by: Lydia Barclay <lydiabarclay@users.noreply.github.com>
1 parent 4d0f402 commit 35415b1

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/libs/ValidationUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ function isValidUSPhone(phoneNumber = '', isCountryCodeOptional?: boolean): bool
321321
}
322322

323323
const parsedPhoneNumber = parsePhoneNumber(phone, {regionCode});
324-
return parsedPhoneNumber.possible && parsedPhoneNumber.regionCode === CONST.COUNTRY.US;
324+
325+
// US territories share the +1 country calling code but have their own ISO region codes.
326+
// We accept these as valid US phone numbers for wallet/bank account verification.
327+
const validUSRegionCodes = [CONST.COUNTRY.US, CONST.COUNTRY.PR, CONST.COUNTRY.GU, CONST.COUNTRY.VI, 'AS', 'MP'];
328+
return parsedPhoneNumber.possible && validUSRegionCodes.includes(parsedPhoneNumber.regionCode ?? '');
325329
}
326330

327331
function isValidPhoneNumber(phoneNumber: string): boolean {

tests/unit/ValidationUtilsTest.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
isValidRegistrationNumber,
1818
isValidRoomName,
1919
isValidTwoFactorCode,
20+
isValidUSPhone,
2021
isValidWebsite,
2122
meetsMaximumAgeRequirement,
2223
meetsMinimumAgeRequirement,
@@ -552,6 +553,40 @@ describe('ValidationUtils', () => {
552553
});
553554
});
554555

556+
describe('isValidUSPhone', () => {
557+
test('Should return true for a standard US phone number', () => {
558+
expect(isValidUSPhone('+12018675309')).toBe(true);
559+
});
560+
561+
test('Should return true for a Puerto Rico phone number (+1-787)', () => {
562+
expect(isValidUSPhone('+17873464732')).toBe(true);
563+
});
564+
565+
test('Should return true for a US Virgin Islands phone number (+1-340)', () => {
566+
expect(isValidUSPhone('+13405551234')).toBe(true);
567+
});
568+
569+
test('Should return true for a Guam phone number (+1-671)', () => {
570+
expect(isValidUSPhone('+16715551234')).toBe(true);
571+
});
572+
573+
test('Should return true for a Northern Mariana Islands phone number (+1-670)', () => {
574+
expect(isValidUSPhone('+16705551234')).toBe(true);
575+
});
576+
577+
test('Should return false for a Canadian phone number (+1-416)', () => {
578+
expect(isValidUSPhone('+14165551234')).toBe(false);
579+
});
580+
581+
test('Should return false for a UK phone number', () => {
582+
expect(isValidUSPhone('+442071234567')).toBe(false);
583+
});
584+
585+
test('Should return false for an empty string', () => {
586+
expect(isValidUSPhone('')).toBe(false);
587+
});
588+
});
589+
555590
describe('isInvalidMerchantValue', () => {
556591
test('Valid merchnt name', () => {
557592
expect(isInvalidMerchantValue('test name')).toBe(false);

0 commit comments

Comments
 (0)