diff --git a/src/CONST.ts b/src/CONST.ts index 0c01958676a2..59ed5b5aad46 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3407,6 +3407,7 @@ const CONST = { SSN_LAST_FOUR: /^(?!0000)[0-9]{4}$/, SSN_FULL_NINE: /^(?!0000)[0-9]{9}$/, NUMBER: /^[0-9]+$/, + PHONE_NUMBER: /^\+?[0-9]{4,17}$/, CARD_NUMBER: /^[0-9]{15,16}$/, CARD_SECURITY_CODE: /^[0-9]{3,4}$/, CARD_EXPIRATION_DATE: /^(0[1-9]|1[0-2])([^0-9])?([0-9]{4}|([0-9]{2}))$/, diff --git a/src/libs/PhoneNumber.ts b/src/libs/PhoneNumber.ts index b0cbbc9176de..f1a83c0a82e8 100644 --- a/src/libs/PhoneNumber.ts +++ b/src/libs/PhoneNumber.ts @@ -16,6 +16,23 @@ function parsePhoneNumber(phoneNumber: string, options?: PhoneNumberParseOptions } const phoneNumberWithoutSpecialChars = phoneNumber.replace(CONST.REGEX.SPECIAL_CHARS_WITHOUT_NEWLINE, ''); + + if (!CONST.REGEX.PHONE_NUMBER.test(phoneNumberWithoutSpecialChars)) { + return { + ...parsedPhoneNumber, + valid: false, + possible: false, + number: { + ...parsedPhoneNumber.number, + e164: phoneNumberWithoutSpecialChars, + international: phoneNumberWithoutSpecialChars, + national: phoneNumberWithoutSpecialChars, + rfc3966: `tel:${phoneNumberWithoutSpecialChars}`, + significant: phoneNumberWithoutSpecialChars, + }, + } as ParsedPhoneNumberInvalid; + } + if (!/^\+11[0-9]{10}$/.test(phoneNumberWithoutSpecialChars)) { return parsedPhoneNumber; }