Skip to content

Commit

Permalink
chore: remove trailing zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
nick134-bit committed Nov 8, 2024
1 parent 6d0c947 commit 8db45af
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions util/amountInputValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('.', '')
Expand Down

0 comments on commit 8db45af

Please sign in to comment.