diff --git a/src/libs/MoneyRequestUtils.ts b/src/libs/MoneyRequestUtils.ts index d76c9325cc0e..7009379e15de 100644 --- a/src/libs/MoneyRequestUtils.ts +++ b/src/libs/MoneyRequestUtils.ts @@ -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); } diff --git a/src/pages/workspace/perDiem/EditPerDiemAmountPage.tsx b/src/pages/workspace/perDiem/EditPerDiemAmountPage.tsx index 3265240ea425..84667e2151ff 100644 --- a/src/pages/workspace/perDiem/EditPerDiemAmountPage.tsx +++ b/src/pages/workspace/perDiem/EditPerDiemAmountPage.tsx @@ -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'); }