react-number-format
react-number-format copied to clipboard
How to allow extensions in phone numbers
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 <NumberFormat allowEmptyFormatting format="+1 (###) ###-####" _mask="_" type="tel" />
. 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!
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 $???????#.##
.
Hi,
is this solved in the latest 5.x version? I am not sure, even after reading the docs.