s-yadav / react-number-format

React component to format numbers in an input or as a text.
MIT License
3.85k stars 404 forks source link

How to allow extensions in phone numbers #586

Open fxlemire opened 2 years ago

fxlemire commented 2 years ago

Discussed in https://github.com/s-yadav/react-number-format/discussions/585

Originally posted by **fxlemire** October 20, 2021 Hi, First of all thanks for this package, it's really great! I love the UX of ``. However, I've noticed that when using format, it then restricts the length of the input. I would love to allow users to optionally provide phone extensions. For example, this is a valid phone number according to `libphonenumber-js`: `+1 (414) 444-1919 #123456789` (`#` or `,`). Is there an easy way with `NumberFormat` ? Either by allowing to go beyond the length of the provided format and leave it unformatted, or providing an optional format at the end? I've tried with `isAllowed` but it seems like it does not go hand-in-hand with `format` 😕 I've made a quick attempt at specifying my custom format, but must have done something wrong because the placeholder I return from the formatting can be erased. Thanks so much for your help!
igorsantos07 commented 2 years ago

Optional chars are common on mask libraries and are definitely a must here. This is also important for money formatting, since you either end up with an empty field, with stuff like $.00 or the user can freely type whatever they want. Having a proper money mask, where anything beyond the first integer is optional, would be very helpful.

Usually such masks are done like $???????#.##.

natterstefan commented 9 months ago

Hi,

is this solved in the latest 5.x version? I am not sure, even after reading the docs.