studiobakers / react-ui-toolkit

Bakers Studio's React-based UI Toolkit
MIT License
15 stars 2 forks source link

feat(input): Add number input localization utility #85

Closed yasincaliskan closed 3 years ago

yasincaliskan commented 3 years ago

Decription

image

edizcelik commented 3 years ago

This may help: https://github.com/globalizejs/globalize/blob/master/doc/api/number/number-parser.md but I think we will need to strict the locales.

edizcelik commented 3 years ago

This answer seems promising. It references this: https://observablehq.com/@mbostock/localized-number-parsing

yasincaliskan commented 3 years ago

Thank you for your suggestions!

yasincaliskan commented 3 years ago

Looks like working well with your help. Thank you @edizcelik 🎉

But there is one more thing. We should think of the following replace scope for other locales. It's working fine with only0123456789.

let parsedNumber = value
.replace(new RegExp(NOT_NUMBER_OR_DECIMAL_POINT_REGEX), "")
...

It couldn't work for any different number of characters. (see last story example) Have you an idea for this?