Skip to content

Commit e48c614

Browse files
authored
Merge pull request Expensify#82695 from Expensify/claude-fixUSPhoneValidationForTerritories
Accept US territory phone numbers in wallet phone validation
2 parents ea6a315 + 4625fa4 commit e48c614

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

src/CONST/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,8 @@ const CONST = {
802802
PR: 'PR',
803803
GU: 'GU',
804804
VI: 'VI',
805+
AS: 'AS',
806+
MP: 'MP',
805807
},
806808
SWIPE_DIRECTION: {
807809
DOWN: 'down',

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: string[] = [CONST.COUNTRY.US, CONST.COUNTRY.PR, CONST.COUNTRY.GU, CONST.COUNTRY.VI, CONST.COUNTRY.AS, CONST.COUNTRY.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', () => {
562+
expect(isValidUSPhone('+17873464732')).toBe(true);
563+
});
564+
565+
test('Should return true for a US Virgin Islands phone number', () => {
566+
expect(isValidUSPhone('+13405551234')).toBe(true);
567+
});
568+
569+
test('Should return true for a Guam phone number', () => {
570+
expect(isValidUSPhone('+16715551234')).toBe(true);
571+
});
572+
573+
test('Should return true for a Northern Mariana Islands phone number', () => {
574+
expect(isValidUSPhone('+16705551234')).toBe(true);
575+
});
576+
577+
test('Should return false for a Canadian phone number', () => {
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)