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

value={formattedNumber} results in country code being shown twice

Open DianaLaa opened this issue 3 years ago • 3 comments

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?

DianaLaa avatar Oct 05 '21 10:10 DianaLaa

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

shiprasharma12 avatar Oct 27 '21 11:10 shiprasharma12

@garganurag893 any updates on this one?

tragicmj avatar Jul 08 '22 04:07 tragicmj

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 }}
  ...
/>

baronchng avatar Aug 06 '22 17:08 baronchng