Skip to main content
Version: v0.23.2

Migrate from react-native-phone-number-input

PhoneField gives you the E.164 number in onChange, with the country and a length check next to it, so there's no ref to call. It formats the number as it's typed for about 50 countries and picks the country from a pasted +44… number. It doesn't bundle libphonenumber, so valid checks the length only; verify the number on your server, as with an SMS code.

- import PhoneInput from 'react-native-phone-number-input';
+ import { PhoneField } from '@elik56a/react-native-pickers';

- const phoneInput = useRef<PhoneInput>(null);
- <PhoneInput
- ref={phoneInput}
- defaultCode="US"
- defaultValue={value}
- onChangeFormattedText={setPhone}
- />
- const valid = phoneInput.current?.isValidNumber(value);
+ <PhoneField
+ defaultCountry="US"
+ value={phone}
+ onChange={(value, { valid }) => {
+ setPhone(value);
+ setValid(valid);
+ }}
+ />
react-native-phone-number-inputReact Native Pickers
defaultCodedefaultCountry, or country + onCountryChange
defaultValue / valuedefaultValue / value, both E.164
onChangeFormattedTextonChange(value): '+12015550123'
onChangeTextonChange's details.nationalNumber
onChangeCountry(country)onCountryChange(code); getCountry(code) for the details
ref.isValidNumber(number)onChange's details.valid, or isValidPhone(digits, country)
ref.getCallingCode()getCountry(code).dialCode
ref.getNumberAfterPossiblyEliminatingZero()done for you: a leading trunk 0 is dropped
placeholderplaceholder (default: an example in the country's format)
disableddisabled
withDarkTheme<PickersProvider colorScheme="dark">, or 'auto'
containerStyle / textInputStyle / codeTextStyle / flagButtonStylestyles={{ field, input, dialCode, countryButton }}
countryPickerPropspreferred, countries, exclude, locale, presentation, sheet
layout="first" | "second"one layout: the flag and code, then the number

See all migration guides for other libraries, and Comparison for when another library is the better choice.