H
H
HalvinBRO2022-03-10 00:36:26
JavaScript
HalvinBRO, 2022-03-10 00:36:26

How to make a mask on input in react?

Hello!

I want to add a mask to input. The input itself is for entering the price.
Here are examples of what I can enter:

  • one;
  • ten;
  • 100;
  • 1000;
  • 10000;
  • 100000;
  • 10000000;
  • 10000.22;


What do I need to see when I type:
  • one;
  • ten;
  • 100;
  • 1000;
  • 10,000;
  • 100,000;
  • 10,000,000;
  • 10 000.22;


I use react-hook-form and react-input-mask to work with the form. I can't find a solution. Perhaps regular seasons will help somehow, but I haven’t really figured them out yet.
In this case, the mask must be dynamic, that is, padding appears in the right places depending on the length of the sum string.

Pennies are not required.

Help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elvis, 2022-03-10
@HalvinBRO

'1234567890.45'.replace(/\B(?=(\d{3})+(?!\d))/g, " ");

'1 234 567 890.45'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question