Skip to content

Commit

Permalink
Merge pull request Expensify#54654 from Expensify/alberto-negative
Browse files Browse the repository at this point in the history
Correctly handle negative numbers for per diem rates
  • Loading branch information
deetergp authored Dec 31, 2024
2 parents 83aae80 + e7f7b7c commit 8921546
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/libs/MoneyRequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ function validateAmount(amount: string, decimals: number, amountMaxLength: numbe
? `^${shouldAllowNegative ? '-?' : ''}\\d{1,${amountMaxLength}}$` // Don't allow decimal point if decimals === 0
: `^${shouldAllowNegative ? '-?' : ''}\\d{1,${amountMaxLength}}(\\.\\d{0,${decimals}})?$`; // Allow the decimal point and the desired number of digits after the point
const decimalNumberRegex = new RegExp(regexString, 'i');
if (shouldAllowNegative) {
return amount === '' || amount === '-' || decimalNumberRegex.test(amount);
}
return amount === '' || decimalNumberRegex.test(amount);
}

Expand Down
3 changes: 1 addition & 2 deletions src/pages/workspace/perDiem/EditPerDiemAmountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ function EditPerDiemAmountPage({route}: EditPerDiemAmountPageProps) {

const newAmount = values.amount.trim();
const backendAmount = newAmount ? convertToBackendAmount(Number(newAmount)) : 0;

if (backendAmount === 0) {
if (backendAmount === 0 || newAmount === '-') {
errors.amount = translate('common.error.fieldRequired');
}

Expand Down

0 comments on commit 8921546

Please sign in to comment.