Gathering detailed insights and metrics for react-native-international-phone-number
Gathering detailed insights and metrics for react-native-international-phone-number
Gathering detailed insights and metrics for react-native-international-phone-number
Gathering detailed insights and metrics for react-native-international-phone-number
⚛️ International mobile phone number input component for React Native 📱
npm install react-native-international-phone-number
Typescript
Module System
Node Version
NPM Version
JavaScript (86.03%)
TypeScript (13.97%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
328 Stars
227 Commits
65 Forks
4 Watchers
7 Branches
19 Contributors
Updated on Jul 10, 2025
Latest Version
0.10.0
Package Id
react-native-international-phone-number@0.10.0
Unpacked Size
105.17 kB
Size
66.49 kB
File Count
15
NPM Version
8.19.4
Node Version
16.20.2
Published on
Jul 10, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
2
1
1$ npm i --save react-native-international-phone-number
OR
1$ yarn add react-native-international-phone-number
Create a react-native.config.js
file at the root of your react-native project with:
1module.exports = { 2 project: { 3 ios: {}, 4 android: {}, 5 }, 6 assets: [ 7 './node_modules/react-native-country-select/lib/assets/fonts', 8 ], 9};
Then link the font to your native projects with:
1npx react-native-asset
npx expo install expo-font
;expo-font
:1 import { useFonts } from 'expo-font'; 2 3 ... 4 5 useFonts({ 6 'TwemojiMozilla': require('./node_modules/react-native-country-select/lib/assets/fonts/TwemojiMozilla.woff2'), 7 }); 8 9 ...
Observation: you need to recompile your project after adding new fonts.
1import React from 'react'; 2import { View, Text } from 'react-native'; 3import PhoneInput, { isValidPhoneNumber } from 'react-native-international-phone-number'; 4 5export class App extends React.Component { 6 constructor(props) { 7 super(props) 8 this.state = { 9 selectedCountry: null, 10 inputValue: '' 11 } 12 } 13 14 function handleSelectedCountry(country) { 15 this.setState({ 16 selectedCountry: country 17 }) 18 } 19 20 function handleInputValue(phoneNumber) { 21 this.setState({ 22 inputValue: phoneNumber 23 }) 24 } 25 26 render(){ 27 return ( 28 <View style={{ width: '100%', flex: 1, padding: 24 }}> 29 <PhoneInput 30 value={this.state.inputValue} 31 onChangePhoneNumber={this.handleInputValue} 32 selectedCountry={this.state.selectedCountry} 33 onChangeSelectedCountry={this.handleSelectedCountry} 34 /> 35 <View style={{ marginTop: 10 }}> 36 <Text> 37 Country:{' '} 38 {`${this.state.selectedCountry?.translations?.eng?.common} (${this.state.selectedCountry?.cca2})`} 39 </Text> 40 <Text> 41 Phone Number: {`${this.state.selectedCountry?.idd?.root} ${this.state.inputValue}`} 42 </Text> 43 <Text> 44 isValid:{' '} 45 {isValidPhoneNumber(this.state.inputValue, this.state.selectedCountry) 46 ? 'true' 47 : 'false'} 48 </Text> 49 </View> 50 </View> 51 ); 52 } 53}
1import React, {useState} from 'react'; 2import {View, Text} from 'react-native'; 3import PhoneInput, { 4 isValidPhoneNumber, 5} from 'react-native-international-phone-number'; 6 7export default function App() { 8 const [selectedCountry, setSelectedCountry] = useState(null); 9 const [inputValue, setInputValue] = useState(''); 10 11 function handleInputValue(phoneNumber) { 12 setInputValue(phoneNumber); 13 } 14 15 function handleSelectedCountry(country) { 16 setSelectedCountry(country); 17 } 18 19 return ( 20 <View style={{width: '100%', flex: 1, padding: 24}}> 21 <PhoneInput 22 value={inputValue} 23 onChangePhoneNumber={handleInputValue} 24 selectedCountry={selectedCountry} 25 onChangeSelectedCountry={handleSelectedCountry} 26 /> 27 <View style={{marginTop: 10}}> 28 <Text> 29 Country:{' '} 30 {`${selectedCountry?.translations?.eng?.common} (${selectedCountry?.cca2})`} 31 </Text> 32 <Text> 33 Phone Number: {`${selectedCountry?.idd?.root} ${inputValue}`} 34 </Text> 35 <Text> 36 isValid:{' '} 37 {isValidPhoneNumber(inputValue, selectedCountry) ? 'true' : 'false'} 38 </Text> 39 </View> 40 </View> 41 ); 42}
1import React, {useState} from 'react'; 2import {View, Text} from 'react-native'; 3import PhoneInput, { 4 ICountry, 5 isValidPhoneNumber, 6} from 'react-native-international-phone-number'; 7 8export default function App() { 9 const [selectedCountry, setSelectedCountry] = useState<null | ICountry>(null); 10 const [inputValue, setInputValue] = useState<string>(''); 11 12 function handleInputValue(phoneNumber: string) { 13 setInputValue(phoneNumber); 14 } 15 16 function handleSelectedCountry(country: ICountry) { 17 setSelectedCountry(country); 18 } 19 20 return ( 21 <View style={{width: '100%', flex: 1, padding: 24}}> 22 <PhoneInput 23 value={inputValue} 24 onChangePhoneNumber={handleInputValue} 25 selectedCountry={selectedCountry} 26 onChangeSelectedCountry={handleSelectedCountry} 27 /> 28 <View style={{marginTop: 10}}> 29 <Text> 30 Country:{' '} 31 {`${selectedCountry?.translations?.eng?.common} (${selectedCountry?.cca2})`} 32 </Text> 33 <Text> 34 Phone Number: {`${selectedCountry?.idd?.root} ${inputValue}`} 35 </Text> 36 <Text> 37 isValid:{' '} 38 {isValidPhoneNumber(inputValue, selectedCountry) ? 'true' : 'false'} 39 </Text> 40 </View> 41 </View> 42 ); 43}
1import React, {useRef} from 'react'; 2import {View, Text} from 'react-native'; 3import PhoneInput, { 4 ICountry, 5 IPhoneInputRef, 6} from 'react-native-international-phone-number'; 7 8export default function App() { 9 const phoneInputRef = useRef<IPhoneInputRef>(null); 10 11 function onSubmitRef() { 12 Alert.alert( 13 'Intermediate Result', 14 `Country: ${inputRef.current?.selectedCountry?.translations?.eng?.common} \nPhone Number: ${inputRef.current?.fullPhoneNumber} \nisValid: ${inputRef.current?.isValid}`, 15 ); 16 } 17 18 return ( 19 <View style={{width: '100%', flex: 1, padding: 24}}> 20 <PhoneInput ref={phoneInputRef} /> 21 <TouchableOpacity 22 style={{ 23 width: '100%', 24 paddingVertical: 12, 25 backgroundColor: '#2196F3', 26 borderRadius: 4, 27 marginTop: 10, 28 }} 29 onPress={onSubmit}> 30 <Text 31 style={{ 32 color: '#F3F3F3', 33 textAlign: 'center', 34 fontSize: 16, 35 fontWeight: 'bold', 36 }}> 37 Submit 38 </Text> 39 </TouchableOpacity> 40 </View> 41 ); 42}
Observation: Don't use the useRef hook combined with the useState hook to manage the phoneNumber and selectedCountry values. Instead, choose to use just one of them (useRef or useState).
1import React, {useState, useEffect} from 'react'; 2import {View, Text, TouchableOpacity, Alert} from 'react-native'; 3import PhoneInput, { 4 ICountry, 5 isValidPhoneNumber, 6} from 'react-native-international-phone-number'; 7import {Controller, FieldValues} from 'react-hook-form'; 8 9interface FormProps extends FieldValues { 10 phoneNumber: string; 11} 12 13export default function App() { 14 const [selectedCountry, setSelectedCountry] = useState<undefined | ICountry>( 15 undefined, 16 ); 17 18 function handleSelectedCountry(country: ICountry) { 19 setSelectedCountry(country); 20 } 21 22 function onSubmit(form: FormProps) { 23 const phoneNumber = `${selectedCountry?.idd?.root} ${form.phoneNumber}`; 24 const isValid = isValidPhoneNumber( 25 form.phoneNumber, 26 selectedCountry as ICountry, 27 ); 28 29 Alert.alert( 30 'Advanced Result', 31 `Country: ${selectedCountry?.translations?.eng?.common} \nPhone Number: ${phoneNumber} \nisValid: ${isValid}`, 32 ); 33 } 34 35 return ( 36 <View style={{width: '100%', flex: 1, padding: 24}}> 37 <Controller 38 name="phoneNumber" 39 control={control} 40 render={({field: {onChange, value}}) => ( 41 <PhoneInput 42 defaultValue="+12505550199" 43 value={value} 44 onChangePhoneNumber={onChange} 45 selectedCountry={selectedCountry} 46 onChangeSelectedCountry={handleSelectedCountry} 47 /> 48 )} 49 /> 50 <TouchableOpacity 51 style={{ 52 width: '100%', 53 paddingVertical: 12, 54 backgroundColor: '#2196F3', 55 borderRadius: 4, 56 }} 57 onPress={handleSubmit(onSubmit)}> 58 <Text 59 style={{ 60 color: '#F3F3F3', 61 textAlign: 'center', 62 fontSize: 16, 63 fontWeight: 'bold', 64 }}> 65 Submit 66 </Text> 67 </TouchableOpacity> 68 </View> 69 ); 70}
Observations:
- You need to use a default value with the following format:
+(country callling code)(area code)(number phone)
- The lib has the mechanism to set the flag and mask of the supplied
defaultValue
. However, if the supplieddefaultValue
does not match any international standard, theinput mask of the defaultValue
will be set to "BR" (please make sure that the default value is in the format mentioned above).
Property | Type | Description |
---|---|---|
container | ViewStyle | Main input container |
flagContainer | ViewStyle | Flag and dropdown container |
flag | TextStyle | Flag emoji styling |
caret | TextStyle | Dropdown arrow |
divider | ViewStyle | Separator line |
callingCode | TextStyle | Country calling code |
input | TextStyle | Phone number input |
Property | Type | Description |
---|---|---|
backdrop | ViewStyle | Modal background overlay |
container | ViewStyle | Modal main container |
content | ViewStyle | Modal content area |
searchContainer | ViewStyle | Search input wrapper |
searchInput | TextStyle | Search input field |
list | ViewStyle | Countries list container |
countryItem | ViewStyle | Individual country row |
flag | TextStyle | Country flag in list |
countryInfo | ViewStyle | Country details container |
callingCode | TextStyle | Calling code in list |
countryName | TextStyle | Country name in list |
sectionTitle | TextStyle | Section headers |
closeButton | ViewStyle | Close button container |
closeButtonText | TextStyle | Close button text |
countryNotFoundContainer | ViewStyle | No results container |
countryNotFoundMessage | TextStyle | No results message |
Prop | Type | Description |
---|---|---|
theme | ITheme | Theme configuration for the component |
language | ILanguage | Language for country names and UI |
defaultValue | string | Default phone number value (format: +(country code)(area code)(number) ) |
value | string | Controlled phone number value |
onChangePhoneNumber | (phoneNumber: string) => void | Callback when phone number changes |
defaultCountry | ICountryCca2 | Default selected country (ISO 3166-1 alpha-2) |
selectedCountry | ICountry | Currently selected country object |
onChangeSelectedCountry | (country: ICountry) => void | Callback when country selection changes |
placeholder | string | Placeholder text for phone input |
phoneInputPlaceholderTextColor | string | Color of placeholder text |
phoneInputSelectionColor | string | Color of text selection |
phoneInputStyles | IPhoneInputStyles | Custom styles for phone input component |
modalStyles | ICountrySelectStyles | Custom styles for country selection modal |
disabled | boolean | Disable the entire phone input |
modalDisabled | boolean | Disable only the country selection modal |
visibleCountries | ICountryCca2[] | Array of country codes to show in modal |
hiddenCountries | ICountryCca2[] | Array of country codes to hide from modal |
popularCountries | ICountryCca2[] | Array of country codes to show in popular section |
customCaret | () => ReactNode | Custom dropdown arrow component |
rtl | boolean | Enable right-to-left layout |
isFullScreen | boolean | Show modal in full screen mode |
modalType | 'bottomSheet' | 'popup' | Type of modal presentation |
modalSearchInputPlaceholderTextColor | string | Color of modal search placeholder text |
modalSearchInputPlaceholder | string | Placeholder text for modal search input |
modalSearchInputSelectionColor | string | Color of modal search text selection |
modalPopularCountriesTitle | string | Title for popular countries section |
modalAllCountriesTitle | string | Title for all countries section |
modalSectionTitleComponent | () => ReactNode | Custom section title component |
modalCountryItemComponent | () => ReactNode | Custom country item component |
modalCloseButtonComponent | () => ReactNode | Custom close button component |
modalSectionTitleDisabled | boolean | Disable section titles in modal |
modalNotFoundCountryMessage | string | Message when no countries found |
disabledModalBackdropPress | boolean | Disable modal close on backdrop press |
removedModalBackdrop | boolean | Remove modal backdrop entirely |
onModalBackdropPress | () => void | Callback when modal backdrop is pressed |
onModalRequestClose | () => void | Callback when modal close is requested |
showModalSearchInput | boolean | Show search input in modal |
showModalCloseButton | boolean | Show close button in modal |
showModalScrollIndicator | boolean | Show scroll indicator in modal |
ref | Ref<IPhoneInputRef> | Ref to access component methods |
Function | Parameters | Return Type | Description |
---|---|---|---|
getAllCountries | () | ICountry[] | Returns an array of all available countries |
getCountriesByCallingCode | (callingCode: string) | ICountry[] | undefined | Returns countries that match the given calling code |
getCountryByCca2 | (cca2: string) | ICountry | undefined | Returns a country by its ISO 3166-1 alpha-2 code |
getCountriesByName | (name: string, language: ILanguage) | ICountry[] | undefined | Returns countries that match the given name in the specified language |
getCountryByPhoneNumber | (phoneNumber: string) | ICountry | undefined | Returns the country that matches the given phone number |
isValidPhoneNumber | (phoneNumber: string, country: ICountry) | boolean | Validates if a phone number is valid for the given country |
The language
prop supports the following values:
Code | Language |
---|---|
ara | Arabic |
bel | Belarusian |
bre | Breton |
bul | Bulgarian |
ces | Czech |
deu | German |
ell | Greek |
eng | English |
est | Estonian |
fin | Finnish |
fra | French |
heb | Hebrew |
hrv | Croatian |
hun | Hungarian |
ita | Italian |
jpn | Japanese |
kor | Korean |
nld | Dutch |
per | Persian |
pol | Polish |
por | Portuguese |
ron | Romanian |
rus | Russian |
slk | Slovak |
spa | Spanish |
srp | Serbian |
swe | Swedish |
tur | Turkish |
ukr | Ukrainian |
urd | Urdu |
zho | Chinese |
zho-Hans | Simplified Chinese |
zho-Hant | Traditional Chinese |
When utilizing this package, you may need to target the PhoneInput component in your automated tests. To facilitate this, we provide a testID props for the PhoneInput component. The testID can be integrated with popular testing libraries such as @testing-library/react-native or Maestro. This enables you to efficiently locate and interact with PhoneInput elements within your tests, ensuring a robust and reliable testing experience.
1const phoneInput = getByTestId('countryPickerPhoneInput'); 2const flagContainerButton = getByTestId('countryPickerFlagContainerButton'); 3const countrySelect = getByTestId('countrySelectSearchInput'); 4const countrySelectBackdrop = getByTestId('countrySelectBackdrop'); 5const countrySelectList = getByTestId('countrySelectList'); 6const countrySelectSearchInput = getByTestId('countrySelectSearchInput'); 7const countrySelectItem = getByTestId('countrySelectItem'); 8const countrySelectCloseButton = getByTestId('countrySelectCloseButton');
Ensure your app is inclusive and usable by everyone by leveraging built-in React Native accessibility features. The accessibility props are covered by this package.
1 $ git clone https://github.com/AstrOOnauta/react-native-international-phone-number.git
Repair, Update and Enjoy 🛠️🚧⚙️
Create a new PR to this repository
No vulnerabilities found.
No security vulnerabilities found.