react-native-phone-input icon indicating copy to clipboard operation
react-native-phone-input copied to clipboard

Get just phone number without country code

Open RShah512 opened this issue 5 years ago • 3 comments

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

RShah512 avatar Dec 20 '18 17:12 RShah512

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

yasir-netlinks avatar Dec 30 '18 10:12 yasir-netlinks

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, '')

boppuh avatar Jun 14 '19 14:06 boppuh

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

RShah512 avatar Jun 14 '19 14:06 RShah512