Normalize odometer input to reject non-numeric characters#85483
Normalize odometer input to reject non-numeric characters#85483neil-marcellini merged 11 commits intomainfrom
Conversation
The odometer input handlers (handleStartReadingChange and handleEndReadingChange) were storing raw input text in state after validation. The isOdometerInputValid function validates the normalized text (with non-numeric characters stripped) but the raw text was stored, allowing letters and symbols to appear in the input field on web/desktop. This normalizes the text via normalizeOdometerText before calling setStartReading/setEndReading so non-numeric characters are stripped at keystroke time rather than only at submit time. Co-authored-by: Chavda Sachin <ChavdaSachin@users.noreply.github.com>
|
I created this PR from an upstream branch since I don't have push access to your fork. To take ownership of this branch and be able to push updates, run: Then you can close this PR and open a new one from your fork. Please mark it as "Ready for review" when it is ready for review. |
|
@MelvinBot one more change, input currently accepts infinite zeroes. please limit those. |
normalizeOdometerText now collapses leading zeroes so users cannot
enter infinite zeroes (e.g. "000" → "0", "007" → "7"). A single
zero before a decimal point is preserved ("0.5" stays "0.5").
Co-authored-by: Chavda Sachin <ChavdaSachin@users.noreply.github.com>
|
Fixed —
Added unit tests covering these cases in |
|
@MelvinBot Mark this ready for review |
|
@ChavdaSachin Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Done — PR has been marked as ready for review. 🚀 |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2026-03-17.at.5.06.35.AM.movAndroid: mWeb ChromeScreen.Recording.2026-03-17.at.5.08.15.AM.moviOS: HybridAppScreen.Recording.2026-03-17.at.5.03.19.AM.moviOS: mWeb SafariScreen.Recording.2026-03-17.at.5.05.20.AM.movMacOS: Chrome / SafariScreen.Recording.2026-03-17.at.4.54.18.AM.mov |
|
@Julesssss Ready to merge |
JmillsExpensify
left a comment
There was a problem hiding this comment.
Those checks make sense to me.
|
@MelvinBot add support for |
normalizeOdometerText now converts commas to periods so both "." and "," work as decimal input in any locale. When this produces multiple decimal points (from group separators that became dots), only the last dot is kept as the decimal separator. This preserves correct handling of German "1.234,5" → "1234.5" and English "1,234.5" → "1234.5" while also allowing English "123,4" → "123.4". Co-authored-by: Chavda Sachin <ChavdaSachin@users.noreply.github.com>
|
@ChavdaSachin Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Added comma support as a decimal separator in
When converting commas to periods produces multiple dots (from group separators), only the last dot is kept as the decimal. Added unit tests covering these cases. |
|
Fixed to support commas, periods and blank space based on preferred locale. VideoScreen.Recording.2026-03-18.at.3.10.48.AM.mov |
|
Assigning @situchan as C+ from this Slack post. |
Code ReviewThe changes look correct and well-structured. Here's a summary of the review: Architecture — Good separation of concerns between the two functions:
This ensures locale formatting (e.g. German Data flow — Traced and verified:
The validator runs on raw input, the display function prepares for state, and the normalizer converts for math — each step is consistent. Leading zero regex (
Tests — Comprehensive coverage for both functions across English/German locales, locale-strict decimal handling, leading zeroes, and display formatting including French and Italian group separators. No blocking issues found. LGTM. |
|
Please ask @MelvinBot to pull main |
|
I can only make changes to this PR when directed by the PR author, an assignee, or an existing co-author. The current assignee is |
|
Codex Review: Didn't find any major issues. 🚀 ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@MelvinBot please merge the latest main |
…terInput Co-authored-by: Chavda Sachin <ChavdaSachin@users.noreply.github.com>
|
Merged the latest |
| * decimal separators depending on locale) and stripping redundant leading zeroes. | ||
| */ | ||
| function prepareTextForDisplay(text: string): string { | ||
| return text.replaceAll(/[^0-9., ]/g, '').replace(/^0+(?=\d)/, ''); |
There was a problem hiding this comment.
Is there a reason for allowing space? It's causing weird bug
Screen.Recording.2026-03-19.at.1.40.13.AM.mov
There was a problem hiding this comment.
Yes some locale uses blank space as group separator(eg. fr).
And for the multiple spaces grouped together I mentioned the slack thread -
Note: I have ignored the cases of multiple group separators grouped together(ie. 12,,3.4) as code would turn ugly and no real gain.
There was a problem hiding this comment.
Further, please refer to the QA tests for better understanding of the locale support.
|
Bug: Cannot add bug.mov |
@situchan only one digit after decimal point is allowed here, so that is expected.(Odometers do not display second digit after decimal point) |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safaridemo.mov |
Julesssss
left a comment
There was a problem hiding this comment.
Looking good, thank you
|
Would you like final review @neil-marcellini? |
neil-marcellini
left a comment
There was a problem hiding this comment.
Looks great, thank you for improving it
|
🚧 @neil-marcellini has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/neil-marcellini in version: 9.3.41-0 🚀
Bundle Size Analysis (Sentry): |
|
🚀 Deployed to production by https://github.com/cristipaval in version: 9.3.41-4 🚀
|
Explanation of Change
The odometer input handlers (
handleStartReadingChangeandhandleEndReadingChange) were storing raw input text in state after validation. TheisOdometerInputValidfunction validates the normalized text (with non-numeric characters already stripped vianormalizeOdometerText) but then the raw, un-normalized text was being stored in state viasetStartReading/setEndReading. This meant non-numeric characters (letters, symbols) passed validation and were displayed in the input field on web/desktop, whereinputMode="decimal"only affects the virtual keyboard layout and does not filter typed characters.This change normalizes the input text via
DistanceRequestUtils.normalizeOdometerText()before storing it in state, so non-numeric characters are stripped at keystroke time rather than only at submit time.This is a clean re-creation of the previous PR #84322, containing only the normalization fix.
Fixed Issues
$ #84220
PROPOSAL: #84220 (comment)
Tests
Offline tests
N/A — This is a client-side input filtering change with no network dependency. The odometer input filtering happens entirely in the React component's change handler.
QA Steps
English (en) locale — comma group separator, period decimal:
3. Try typing letters (e.g., "abc") into the Start reading and End reading fields
4. Verify that only numeric characters (digits, period, and comma) are accepted
5. Try pasting text with mixed characters (e.g., "abc123.4def")
6. Verify only "123.4" appears in the field
7. Type "1,234.5" and verify it is accepted correctly
8. Type "000" and verify it is normalized to "0" (no infinite leading zeroes)
Italian (it) locale — period group separator, comma decimal:
9. Switch the app locale to Italian
10. Type "1.234,5" into the Start reading field
11. Verify it is accepted and displayed correctly (period as group separator, comma as decimal)
12. Try typing "abc" and verify letters are rejected
French (fr) locale — space group separator, comma decimal:
13. Switch the app locale to French
14. Type "1 234,5" into the Start reading field
15. Verify it is accepted and displayed correctly (space as group separator, comma as decimal)
16. Try typing "abc" and verify letters are rejected
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Web: Chrome
Tested on web — odometer input fields correctly reject non-numeric characters. Typing "abc123" results in only "123" being displayed. Valid decimal input like "12345.6" is accepted correctly.
Android: Native
N/A —
inputMode="decimal"already shows numeric keyboard on mobile, preventing non-numeric input.Android: mWeb Chrome
N/A —
inputMode="decimal"already shows numeric keyboard on mobile, preventing non-numeric input.iOS: Native
N/A —
keyboardType="decimal-pad"already shows numeric keyboard on iOS, preventing non-numeric input.iOS: mWeb Safari
N/A —
inputMode="decimal"already shows numeric keyboard on mobile, preventing non-numeric input.MacOS: Chrome / Safari
Same behavior as Web: Chrome — non-numeric characters are stripped at keystroke time.