react-native-phone-number-input
react-native-phone-number-input copied to clipboard
value={formattedNumber} results in country code being shown twice
I have a formatted number and I want to set this as the value (or defaultValue, either), for an edit screen. However, I cannot set the original phone number in <PhoneInput>. For example, the current data is +31612345678 In my edit screen, I set value={currentPhoneNumber}
What it displays is +31 +31612345678
How can I convince PhoneInput that my current value already has the +31 prefix and that it needs to be stripped off?
Any update over this? As i want to use it in my edit profile screen. where i need to show the prefilled value. but its showing me calling code 2 times
@garganurag893 any updates on this one?
import { PhoneNumberUtil } from 'google-libphonenumber';
const phoneUtil = PhoneNumberUtil.getInstance();
const parsedNo = phoneUtil.parse('your number', '');
if (parsedNo.hasNationalNumber()) {
const nationalNumber = parsedNo.getNationalNumberOrDefault().toString();
// store this nationalNumber in state
}
<PhoneInput
...
textInputProps={{ value: phoneNumber }}
...
/>