thegamenicorus / react-native-phone-input

Phone input box for React Native
https://www.npmjs.com/package/react-native-phone-input
MIT License
394 stars 447 forks source link

Get just phone number without country code #79

Open RShah512 opened 5 years ago

RShah512 commented 5 years ago

Is there a way to separate out country code from the phone number?

yasir-netlinks commented 5 years ago

@RShah512 hi , have you found a way to do this ?

boppuh commented 5 years ago

Use string replace to replace the + and the first occurrence of the country code with an empty string. Auto-format must be false, or you must replace the other formatting characters and blank spaces with an empty string, as well.

const countryCode = this.phone.getCountryCode()
let phoneNumber = this.phone.getValue()
phoneNumber = phoneNumber.replace('+','')
phoneNumber = phoneNumber.replace(countryCode, '')
RShah512 commented 5 years ago

@yasir-netlinks Yes, I used getCountryCode function onSelectCountry property and then like @boppuh answer, I used replace to remove the '+' sign.