Skip to content

[$175] Phone-number validation error displayed when set 9833330123 as phone number #104964

Open

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.20-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #104372
Email or phone of affected tester (no customers): gocemate+workseee5@gmail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: windows 10/chrome
App Component: User Settings

Action Performed:

  1. Open Personal information under profile settings.
  2. Complete the other required fields with valid test data of US address.
  3. In the phone field, enter 9833330123

Expected Result:

There should be no error validation message

Actual Result:

Phone-number validation error is displayed

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

Bug7294807_1792787692585.Recording__1929.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Julia Ponikarchuk
Bug ID: 7294807

Upwork Automation - Do Not Edit

Activity

  1. applause-bot commented on Oct 26, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/1987a4ffa16c0d3cd8e16fc432dbf58243987ba6a734d409783d64862cfcd58c

  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 26, 2026
  3. MelvinBot commented on Oct 26, 2026

    @MelvinBot
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    On Profile > Personal information, entering 9833330123 with a US address shows a phone-number error.

    What is the root cause of that problem?

    The phone check ignores the US address. Instead, it adds the calling code from the Onyx countryCode key, which comes from the user's IP location.

    • PrivatePersonalDetailsPage.tsx:138 calls appendCountryCode(phoneValue, countryCode). countryCode comes from ONYXKEYS.COUNTRY_CODE (line 58).
    • appendCountryCode adds +<IP country code>. If that result isn't a possible number, the function adds only +. In that case, 9833330123 becomes +9833330123, which reads as an Iranian (+98) number that is too short.
    • isValidPhoneNumber then rejects it.

    Upgrade awesome-phonenumber to 6.11.0 so newer US area codes like 983 validate is in 9.5.20-0. It fixed +19833330123, so the number works when the code adds +1. The tester is likely outside the US, so the code never adds +1. That PR's author was likely on a US IP, which explains why the same steps passed for them.

    Saving has the same flaw. updatePrivatePersonalDetails formats the number with the IP country code. For example, a user in India with a US address would save +919833330123.

    What changes do you think we should make in order to solve the problem?

    When the user hasn't typed a +, derive the calling code from the address country selected in the form. For example, use getCountryCodeForRegionCode('US') from awesome-phonenumber to get 1. Fall back to the Onyx countryCode only when no address country is selected.

    1. Add a small LoginUtils helper that takes the phone, the region, and the fallback code.
    2. Use the helper in PrivatePersonalDetailsPage validation and in updatePrivatePersonalDetails so validation and the saved E.164 value match.
    3. Apply the same change to MissingPersonalDetails/subPages/PhoneNumber.tsx, which uses the same pattern.
    4. Add a unit test: 9833330123 with country US and an IP code of 44 should be valid and format to +19833330123.

    What alternative solutions did you explore? (Optional)

    Stop the +${phone} fallback in appendCountryCode. This would hide the bad +98 parse, but it wouldn't add the correct +1. The number would still be saved with the wrong country code.

    Confidence and open questions

    Confidence is medium. The code path is confirmed. I didn't confirm the tester's IP-based countryCode, and I didn't run the library against +<tester code>9833330123. You can confirm the cause if you see either of these:

    • The tester's Onyx countryCode is not 1.
    • Running Onyx.set('countryCode', 44) on a US IP reproduces the error.

    If the tester's countryCode is 1, this root cause is wrong.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/104964) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Oct 26, 2026
  5. melvin-bot commented on Oct 26, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @parasharrajat (External)

  6. changed the title [-]Phone-number validation error displayed when set 9833330123 as phone number[/-] [+][$175] Phone-number validation error displayed when set 9833330123 as phone number[/+] on Oct 26, 2026
  7. melvin-bot commented on Oct 26, 2026

    @melvin-bot
  8. camesenin commented on Oct 26, 2026

    @camesenin
  9. melvin-bot commented on Oct 26, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  10. shilo1979jk commented on Oct 26, 2026

    @shilo1979jk

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    In Settings > Profile > Personal information (PrivatePersonalDetailsPage) — and in the MissingPersonalDetails card-shipping/reveal wizard (MissingPersonalDetails/subPages/PhoneNumber.tsx) — entering a 10-digit US phone number without a +1 prefix (such as 9833330123) while a US address is selected ignores the form's selected address country and uses the client's IP geolocation calling code (ONYXKEYS.COUNTRY_CODE). Depending on the user's IP calling code, this either triggers the "Please enter a valid phone number" validation error (e.g., countryCode = 48 or 380) or silently formats and saves the number under a foreign calling code (e.g., +449833330123 or +919833330123).

    What is the root cause of that problem?

    1. PR #104372 upgraded awesome-phonenumber to 6.11.0, so +19833330123 is valid when the +1 calling code is prepended.

    2. However, in src/pages/settings/Profile/PersonalDetails/PrivatePersonalDetailsPage.tsx, phone validation ignores the country selected on the form (values[INPUT_IDS.COUNTRY]) and passes countryCode from useOnyx(ONYXKEYS.COUNTRY_CODE) (IP geolocation):

      const phoneWithCountryCode = appendCountryCode(phoneValue, countryCode);
      if (!isValidPhoneNumber(phoneWithCountryCode)) {
          errors[INPUT_IDS.PHONE_NUMBER] = translate('common.error.phoneNumber');
      }
    3. In src/libs/LoginUtils.ts (appendCountryCode), testing 9833330123 against awesome-phonenumber@6.11.0 and the app's parsePhoneNumber / isValidPhoneNumber produces two failure modes when countryCode !== 1:

      IP countryCode appendCountryCode('9833330123', countryCode) isValidPhoneNumber (.possible) formatE164PhoneNumber output
      1 (US) +19833330123 true +19833330123
      48 (PL), 380 (UA) +9833330123 (+48.../+380... is not possible -> falls back to +${phone}, parsed as Iran +98 with 8 digits) false (throws validation error) +9833330123
      44 (GB), 49 (DE), 91 (IN) +449833330123 / +499833330123 / +919833330123 true (silently misinterprets US number as foreign number) +449833330123 / +499833330123 / +919833330123
    4. There are five coupled call sites across validation, step-draft formatting, and API submission that must stay in sync:

      • Site 1 — Profile validation: PrivatePersonalDetailsPage.tsx:138 (appendCountryCode(phoneValue, countryCode)).
      • Site 2 — MissingPersonalDetails step validation: src/pages/MissingPersonalDetails/subPages/PhoneNumber.tsx:29 (appendCountryCode(values[INPUT_IDS.PHONE_NUMBER], countryCode)).
      • Site 3 — MissingPersonalDetails step onSubmit draft formatting: src/pages/MissingPersonalDetails/subPages/PhoneNumber.tsx:60 calls formatE164PhoneNumber(values[INPUT_IDS.PHONE_NUMBER].trim(), countryCode) before saving the step value into ONYXKEYS.FORMS.PERSONAL_DETAILS_FORM_DRAFT. If line 60 is not updated alongside validation, submitting the phone step on IP 91 or 44 writes +919833330123 / +449833330123 (with a leading +) into the draft, and later calls to appendCountryCode will return it unchanged because phone.startsWith('+') is already true.
      • Site 4 — Profile submission: updatePrivatePersonalDetails in src/libs/actions/PersonalDetails.ts calls LoginUtils.formatE164PhoneNumber(values.phoneNumber?.trim() ?? '', countryCode).
      • Site 5 — Card shipping / reveal submission: buildSetPersonalDetailsAndShipExpensifyCardsParams in src/libs/actions/PersonalDetails.ts (shared by updatePersonalDetailsAndShipExpensifyCards, MissingPersonalDetailsContent.tsx, MissingPersonalDetailsValidateCodePage.tsx, ExpensifyCardVerifyAccountPage.tsx, and ExpensifyCardPage/index.tsx) also calls LoginUtils.formatE164PhoneNumber(values.phoneNumber?.trim() ?? '', countryCode).

    What changes do you think we should make in order to solve the problem?

    When the phone input does not have an explicit + calling code, resolve the default calling code from the selected address country first, falling back to ONYXKEYS.COUNTRY_CODE when no valid address country is present.

    1. Add and export getPhoneCallingCode in src/libs/LoginUtils.ts:
      (no-restricted-imports in config/eslint/eslint.config.mjs only restricts parsePhoneNumber from awesome-phonenumber, so getCountryCodeForRegionCode can be imported directly; normalizing via getCountryCode from @libs/CountryUtils handles legacy stored country names like 'United States'):

      import {getCountryCodeForRegionCode} from 'awesome-phonenumber';
      import {getCountryCode} from './CountryUtils';
      
      function getPhoneCallingCode(country: string | undefined, fallbackCountryCode: number): number {
          const normalizedCountry = getCountryCode(country);
          const callingCode = normalizedCountry ? getCountryCodeForRegionCode(normalizedCountry) : 0;
          return callingCode > 0 ? callingCode : fallbackCountryCode;
      }
    2. In src/pages/settings/Profile/PersonalDetails/PrivatePersonalDetailsPage.tsx:
      Move the existing const effectiveCountry = values[INPUT_IDS.COUNTRY] ?? ''; declaration (currently at line 155) above the phone validation block (line 134) and pass getPhoneCallingCode(effectiveCountry, countryCode):

      const effectiveCountry = values[INPUT_IDS.COUNTRY] ?? '';
      const phoneValue = values[INPUT_IDS.PHONE_NUMBER] ?? '';
      if (!isRequiredFulfilled(phoneValue)) {
          errors[INPUT_IDS.PHONE_NUMBER] = translate('common.error.fieldRequired');
      } else {
          const phoneWithCountryCode = appendCountryCode(phoneValue, getPhoneCallingCode(effectiveCountry, countryCode));
          if (!isValidPhoneNumber(phoneWithCountryCode)) {
              errors[INPUT_IDS.PHONE_NUMBER] = translate('common.error.phoneNumber');
          }
      }
    3. In src/pages/MissingPersonalDetails/subPages/PhoneNumber.tsx:
      Because an existing address country may come from stored privatePersonalDetails (normalized in MissingPersonalDetailsContent.tsx via personalDetailsValues) rather than draftValues, compute effectiveCountryCode from personalDetailsValues[INPUT_IDS.COUNTRY] and use it in both validate (line 29) and onSubmit (line 60):

      const effectiveCountryCode = getPhoneCallingCode(personalDetailsValues[INPUT_IDS.COUNTRY], countryCode);
      • In validate (with [translate, effectiveCountryCode] dependencies):
        const phoneNumber = appendCountryCode(values[INPUT_IDS.PHONE_NUMBER], effectiveCountryCode);
      • In onSubmit (line 60):
        const formattedPhoneNumber = formatE164PhoneNumber(values[INPUT_IDS.PHONE_NUMBER].trim(), effectiveCountryCode);
    4. In src/libs/actions/PersonalDetails.ts:
      Update both buildSetPersonalDetailsAndShipExpensifyCardsParams (line 61) and updatePrivatePersonalDetails (line 547):

      phoneNumber: LoginUtils.formatE164PhoneNumber(
          values.phoneNumber?.trim() ?? '',
          LoginUtils.getPhoneCallingCode(values.country, countryCode),
      ) ?? '',
    5. Add unit tests in tests/unit/LoginUtilsTest.ts (and personal details action/step tests):

      • getPhoneCallingCode('US', 48) and getPhoneCallingCode('United States', 48) return 1; getPhoneCallingCode('', 48) returns 48.
      • With country = 'US' and IP countryCode = 48 (which previously failed validation as +9833330123) or 91 (which previously misformatted as +919833330123), appendCountryCode and formatE164PhoneNumber produce '+19833330123', while explicit international input like '+442071234567' remains '+442071234567'.

    What alternative solutions did you explore? (Optional)

    • Updating only PhoneNumber.tsx validation and updatePrivatePersonalDetails (as in MelvinBot's proposal): Incomplete because PhoneNumber.tsx:60 formats the number with countryCode before writing to the form draft, and buildSetPersonalDetailsAndShipExpensifyCardsParams formats the number with countryCode when submitting the card-shipping/reveal flow.
    • Falling back to CONST.DEFAULT_COUNTRY_CODE (1) inside appendCountryCode: Rejected because it breaks non-US addresses and affects 25+ unrelated login/invite/wallet call sites across the app.
  11. bhomvratrai-glitch commented on Oct 26, 2026

    @bhomvratrai-glitch

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    In Settings > Profile > Personal information (PrivatePersonalDetailsPage), entering a 10-digit US phone number without the +1 prefix (e.g., 9833330123) alongside a US address displays the validation error "Please enter a valid phone number" whenever the user's IP geolocation calling code (ONYXKEYS.COUNTRY_CODE) is outside North America.

    What is the root cause of that problem?

    1. In src/pages/settings/Profile/PersonalDetails/PrivatePersonalDetailsPage.tsx (lines 134–142):

      const phoneValue = values[INPUT_IDS.PHONE_NUMBER] ?? '';
      if (!isRequiredFulfilled(phoneValue)) {
          errors[INPUT_IDS.PHONE_NUMBER] = translate('common.error.fieldRequired');
      } else {
          const phoneWithCountryCode = appendCountryCode(phoneValue, countryCode);
          if (!isValidPhoneNumber(phoneWithCountryCode)) {
              errors[INPUT_IDS.PHONE_NUMBER] = translate('common.error.phoneNumber');
          }
      }

      countryCode is obtained on line 58 directly from useOnyx(ONYXKEYS.COUNTRY_CODE) (which is set by the backend based on the client's current IP geolocation, e.g. 380 for Ukraine, 48 for Poland, 44 for UK, 91 for India).

    2. In src/libs/LoginUtils.ts (appendCountryCode, lines 22–31):

      function appendCountryCode(phone: string, countryCode: number): string {
          if (phone.startsWith('+')) {
              return phone;
          }
          const phoneWithCountryCode = `+${countryCode}${phone}`;
          if (parsePhoneNumber(phoneWithCountryCode).possible) {
              return phoneWithCountryCode;
          }
          return `+${phone}`;
      }

      When an offshore QA tester or international user tests/enters a 10-digit US number without +1 (such as 9833330123):

      • appendCountryCode first attempts +${countryCode}${phone} (e.g. +3809833330123 or +489833330123). Because local phone numbers in those countries expect 9 digits, 10 digits makes parsePhoneNumber.possible return false.
      • appendCountryCode then falls back to +${phone} (+9833330123).
      • In awesome-phonenumber, +98 is the country calling code for Iran (IR). Because Iranian phone numbers require 10 digits after +98, having only 8 digits (33330123) makes parsePhoneNumber('+9833330123').possible return false.
      • isValidPhoneNumber('+9833330123') returns false, causing PrivatePersonalDetailsPage to flag errors[INPUT_IDS.PHONE_NUMBER].
    3. A matching issue exists upon submission in src/pages/settings/Profile/PersonalDetails/PrivatePersonalDetailsConfirmValidateCodePage.tsx (lines 28 and 70):

      const [countryCode = CONST.DEFAULT_COUNTRY_CODE] = useOnyx(ONYXKEYS.COUNTRY_CODE);
      ...
      const handleSubmitForm = (validateCode: string) => {
          updatePrivatePersonalDetails(values, validateCode, countryCode);
      };

      In src/libs/actions/PersonalDetails.ts (line 547), formatE164PhoneNumber(values.phoneNumber?.trim() ?? '', countryCode) uses the passed countryCode to normalize the E.164 phone number. Because countryCode is the IP geolocation, it also fails or formats incorrectly when the user entered a national number matching their selected address country.

    What changes do you think we should make in order to solve the problem?

    1. In src/pages/settings/Profile/PersonalDetails/PrivatePersonalDetailsPage.tsx:
      Derive the phone number's country calling code from the address country (values[INPUT_IDS.COUNTRY]), falling back to countryCode (from ONYXKEYS.COUNTRY_CODE) or CONST.DEFAULT_COUNTRY_CODE (1):

      const effectiveCountry = values[INPUT_IDS.COUNTRY] ?? '';
      const effectiveCallingCode = effectiveCountry === CONST.COUNTRY.US ? CONST.DEFAULT_COUNTRY_CODE : countryCode;
      const phoneWithCountryCode = appendCountryCode(phoneValue, effectiveCallingCode);
    2. In src/pages/settings/Profile/PersonalDetails/PrivatePersonalDetailsConfirmValidateCodePage.tsx:
      Derive the calling code passed to updatePrivatePersonalDetails from the draft's address country (values.country === CONST.COUNTRY.US ? CONST.DEFAULT_COUNTRY_CODE : countryCode) so the normalized E.164 value in LoginUtils.formatE164PhoneNumber is also consistently formatted as +19833330123.

    3. In src/libs/LoginUtils.ts (appendCountryCode):
      As a secondary safeguard, when parsePhoneNumber('+${countryCode}${phone}').possible is false, check whether parsePhoneNumber('+${CONST.DEFAULT_COUNTRY_CODE}${phone}').possible is true before falling back to +${phone}. This ensures standard 10-digit North American numbers gracefully normalize to +1 across all callers even if a component does not explicitly override the calling code.

    What alternative solutions did you explore? (Optional)

    • Only modifying appendCountryCode: While falling back to CONST.DEFAULT_COUNTRY_CODE in appendCountryCode resolves validation, PrivatePersonalDetailsPage and PrivatePersonalDetailsConfirmValidateCodePage are explicitly tied to the user's selected address country. Using effectiveCallingCode ensures the validation and submission payloads align with the country selected on the form.
  12. khizzcr7 commented on Oct 26, 2026

    @khizzcr7

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    On Profile > Personal information, entering 9833330123 (no +1 prefix) while a US address is selected shows a phone-number validation error, even though the number should be valid for the selected US address.

    What is the root cause of that problem?

    The phone check does not use the address country selected in the form. Verified on main in src/pages/settings/Profile/PersonalDetails/PrivatePersonalDetailsPage.tsx: line 58 reads countryCode from ONYXKEYS.COUNTRY_CODE, which is the IP-geolocation calling code, and the validate function (around line 138) calls appendCountryCode(phoneValue, countryCode) and then isValidPhoneNumber on the result. The form's selected country (values[INPUT_IDS.COUNTRY], used as effectiveCountry for the zip-code check just below) is never used for the phone check. So when the IP calling code disagrees with the selected address country, validation prefixes the wrong calling code, and a valid US number fails. This holds regardless of the tester's exact IP code, which is why the fix removes the IP dependence instead of chasing one tester's location.

    What changes do you think we should make to fix this issue?

    In the validate function of PrivatePersonalDetailsPage.tsx, derive the calling code from the form's selected country first: look up the calling code for values[INPUT_IDS.COUNTRY] from the app's existing country data, falling back to the Onyx countryCode only when the form country is empty. Pass that code to appendCountryCode and keep the existing isValidPhoneNumber gate unchanged, so genuinely invalid numbers still error and no number is silently re-addressed to a different country.

    What alternative solutions did you explore? (Optional)

    Leaving the IP-based code and special-casing US numbers was rejected: it would fix only this one number and would still mis-validate every other form-country/IP mismatch.

    What will you verify?

    • US form country with a non-US IP calling code, entering 9833330123: no validation error (the failing case).
    • US form country with a US IP calling code, same number: still no error.
    • A genuinely invalid number under a US form country: still errors.
    • A non-US form country: validation uses that country's code, not the IP code.
    • Existing PersonalDetails form tests pass, plus a new unit test for the form-country/IP mismatch case.
  13. 8 remaining items

  14. melvin-bot commented on Nov 3, 2026

    @melvin-bot

    @parasharrajat 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  15. parasharrajat commented on Nov 3, 2026

    @parasharrajat
    Member

    @MelvinBot implement this #104964 (comment)

    🎀 👀 🎀 C+ reviewed

  16. MelvinBot commented on Nov 3, 2026

    @MelvinBot
    Contributor

    🤖 Draft PR created: Use the address country's calling code when validating personal details phone numbers
    Please mark it as "Ready for review" or ask me to do that for you when it is ready for review.

    Bare phone numbers (no +) now use the calling code of the address country in the form. The IP-based code is only a fallback.

    • I confirmed the cause on main. With a Ukrainian IP code (380), 9833330123 becomes +9833330123 and fails validation. UK and India IP codes pass but save the wrong calling code, for example +449833330123.
    • The fix covers Profile > Personal information (validation and save), the Missing Personal Details phone step, and the Expensify Card save path.
    • It also handles the points emkhalid raised. Legacy country names like "United States" resolve correctly. The Missing Personal Details phone step reads the country from the saved form values. The phone library stays wrapped in @libs/PhoneNumber.
    Testing
    • Unit tests (LoginUtilsTest, CloseAccountPageTest), typecheck, and lint passed.
    • I couldn't run the web UI check because the test browser session showed a blank page. To check manually, run Onyx.set('countryCode', 380), then enter 9833330123 with a US address on Profile > Personal information.
  17. melvin-bot commented on Nov 6, 2026

    @melvin-bot

    @parasharrajat Whoops! This issue is 2 days overdue. Let's get this updated quick!

  18. jeffrey-graham commented on Nov 7, 2026

    @jeffrey-graham
  19. melvin-bot commented on Nov 7, 2026

    @melvin-bot
  20. melvin-bot commented on Nov 9, 2026

    @melvin-bot

    @parasharrajat this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

  21. melvin-bot commented on Nov 10, 2026

    @melvin-bot

    @parasharrajat Still overdue 6 days?! Let's take care of this!

  22. melvin-bot commented on Nov 12, 2026

    @melvin-bot

    @parasharrajat 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

  23. expensify-chore-bot commented on Nov 19, 2026

    @expensify-chore-bot

    This issue has not been updated in over 14 days. @parasharrajat eroding to Weekly issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorWeeklyKSv2

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions