react-phone-input
react-phone-input copied to clipboard
Figure out country code automatically?
Hi,
This component seems to be only good for registration forms (i.e. when the phone number doesn't exist yet), because the selected country always has to be supplied manually.
But what if I want to use this component to edit an already existing phone number? Why do I still need to specify the selected country manually? Can you make it so that the country is automatically parsed from the phone number's country code?
For example, if I provide +37255530593
as the value, it should automatically set Estonia as the country code. Right now it always sets Afghanistan, (unless another country is manually provided)
With the way it is now, I first need to use some other library to parse the country from the phone number, and then supply that country to ReactPhoneInput
, which is a lot of redundant work.
same situation when updating existing phone number. Input show default country code while phone number as different country dial up code.
I'm currently using Google's libphonenumber-js instead (https://github.com/catamphetamine/libphonenumber-js) - it has everything you need, including automatically parsing the country as the user types in the phone!
Thanks @jnazander ....That did the magic....