From 64883fb1de3d63400d9c0938126f06a341d8685e Mon Sep 17 00:00:00 2001 From: nick134 <76399455+nick134-bit@users.noreply.github.com> Date: Fri, 8 Nov 2024 18:15:44 +0100 Subject: [PATCH] chore: remove trailing zeros (#597) --- util/amountInputValidation.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/util/amountInputValidation.ts b/util/amountInputValidation.ts index b1e02788..fbefc56a 100644 --- a/util/amountInputValidation.ts +++ b/util/amountInputValidation.ts @@ -6,12 +6,14 @@ */ export const amountInputValidation = (input: string): string => { const amount = input. - // Limiting the number of characters to be 32 + // Limiting the number of characters to be 32 slice(0, 32). - // Disallowing leading decimal place and multiple zeros before decimal place + // Disallowing leading decimal place and multiple zeros before decimal place replace(/^(?:\.|0{2,}\.)/u, '0.'). - // Eliminating multiple leading zeros before the numbers between 1-9 - replace(/^0+(?=[0-9])/u, '') + // Eliminating multiple leading zeros before the numbers between 1-9 + replace(/^0+(?=[0-9])/u, ''). + // Remove excess zeros after decimal point + replace(/\.(\d+?)0{2,}$/u, '.$10') // Ensuring multiple decimal points can't be used return input.indexOf('.') !== amount.lastIndexOf('.') ? amount.slice(0, amount.indexOf('.') + 1) + amount.slice(amount.indexOf('.')).replaceAll('.', '')