Let's get real, it sucks when things don't behave the way they should. User-friendliness is underrated when it comes to form input fields.
When providing a user with an input field to write a number and it doesn't get formatted as how normally numbers are, it gives the user another task of counting zero's, honestly it sucks 😠.
Tried searching for a solution online but couldn't find what I wanted 😩, that's when I decided to solve it myself and help others by compiling the solution into a library and place it in a place where anyone can find it.
Top comments (5)
Have you tried
toLocaleString
? That also solves the problem of knowing when to use , as the decimal point and . as the thousands separator.Hello Matt , thanks for pointing this out, yes i tried using it but didn't get the flexibility that was needed on the input field. It formatted the number but it took control of the cursor, that's why i opted regex.
Thanks for the insight.
Amazing 🔥 🔥
Very useful, i recommend