sample-usr / react-phone-input

A simple react component to format phone number as the user types
MIT License
88 stars 80 forks source link

Figure out country code automatically? #67

Open jnazander opened 6 years ago

jnazander commented 6 years ago

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.

BuildWithLal commented 6 years ago

same situation when updating existing phone number. Input show default country code while phone number as different country dial up code.

jnazander commented 6 years ago

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!

BuildWithLal commented 6 years ago

Thanks @jnazander ....That did the magic....