diff --git a/util/amountInputValidation.ts b/util/amountInputValidation.ts index b1e02788..927660ec 100644 --- a/util/amountInputValidation.ts +++ b/util/amountInputValidation.ts @@ -6,12 +6,13 @@ */ 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, ''). + replace(/\.?0+$/u, '') // Ensuring multiple decimal points can't be used return input.indexOf('.') !== amount.lastIndexOf('.') ? amount.slice(0, amount.indexOf('.') + 1) + amount.slice(amount.indexOf('.')).replaceAll('.', '')