Skip to content

Commit 8921546

Browse files
authored
Merge pull request Expensify#54654 from Expensify/alberto-negative
Correctly handle negative numbers for per diem rates
2 parents 83aae80 + e7f7b7c commit 8921546

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/libs/MoneyRequestUtils.ts

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ function validateAmount(amount: string, decimals: number, amountMaxLength: numbe
5050
? `^${shouldAllowNegative ? '-?' : ''}\\d{1,${amountMaxLength}}$` // Don't allow decimal point if decimals === 0
5151
: `^${shouldAllowNegative ? '-?' : ''}\\d{1,${amountMaxLength}}(\\.\\d{0,${decimals}})?$`; // Allow the decimal point and the desired number of digits after the point
5252
const decimalNumberRegex = new RegExp(regexString, 'i');
53+
if (shouldAllowNegative) {
54+
return amount === '' || amount === '-' || decimalNumberRegex.test(amount);
55+
}
5356
return amount === '' || decimalNumberRegex.test(amount);
5457
}
5558

src/pages/workspace/perDiem/EditPerDiemAmountPage.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ function EditPerDiemAmountPage({route}: EditPerDiemAmountPageProps) {
4848

4949
const newAmount = values.amount.trim();
5050
const backendAmount = newAmount ? convertToBackendAmount(Number(newAmount)) : 0;
51-
52-
if (backendAmount === 0) {
51+
if (backendAmount === 0 || newAmount === '-') {
5352
errors.amount = translate('common.error.fieldRequired');
5453
}
5554

0 commit comments

Comments
 (0)