From 6466f13827aa007fe857c0b53b24bbe5f01954fa Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 30 Dec 2024 13:52:08 +0100 Subject: [PATCH 1/2] Allow negative symbol --- src/libs/MoneyRequestUtils.ts | 3 +++ 1 file changed, 3 insertions(+) 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); } From e7f7b7c2b6b90b4a2ba13820badfd4360ff8a61e Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 30 Dec 2024 14:08:24 +0100 Subject: [PATCH 2/2] show error for negative symbol --- src/pages/workspace/perDiem/EditPerDiemAmountPage.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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'); }