🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

react-native-phone-entry

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-phone-entry

Simple and fully modifiable Phone Number Input Component for React Native

0.2.2
latest
Source
npm
Version published
Maintainers
1
Created
Source

react-native-phone-entry

npm version License

react-native-phone-entry is a simple and fully modifiable Phone Number Input Component for React Native that provides an intuitive interface for entering and validating international phone numbers. It includes country code selection, number formatting, and validation features.

Looking for an OTP input component to verify phone numbers? Check out react-native-otp-entry - a simple and fully modifiable OTP Input Component for React Native that provides an intuitive interface for entering one-time passwords.

Autopick Feature

A feature that automatically picks the right country while typing the phone number.

Masking Feature

A feature that picks a right mask based on the country code.

Features

  • 🌍 International phone number input with country picker
  • 📱 Automatic phone number formatting based on country
  • 🔍 Dynamic country and mask adaptation based on typed country code
  • ✨ Highly customizable appearance and styling
  • 🎯 Phone number validation using Google's libphonenumber
  • 🎨 Dark theme support
  • ♿ Accessibility support
  • 💪 Written in TypeScript

Installation

npm install react-native-phone-entry

# or

yarn add react-native-phone-entry

Usage

  • Import the PhoneInput component:
import { PhoneInput, isValidNumber } from 'react-native-phone-entry';
  • Basic usage:
export default function App() {
  const [countryCode, setCountryCode] = useState < CountryCode > 'US';
  return (
    <PhoneInput
      defaultValues={{
        countryCode: 'US',
        callingCode: '+1',
        phoneNumber: '+1',
      }}
      onChangeText={(text) =>
        console.log(
          'Phone number:',
          text,
          'isValidNumber:',
          isValidNumber(text, countryCode)
        )
      }
      onChangeCountry={(country) => {
        console.log('Country:', country);
        setCountryCode(country.cca2);
      }}
    />
  );
}
  • Advanced usage with customization:
<PhoneInput
  defaultValues={{
    countryCode: 'US',
    callingCode: '+1',
    phoneNumber: '+123456789',
  }}
  value="+123456789"
  onChangeText={(text) => console.log('Phone number:', text)}
  onChangeCountry={(country) => console.log('Country:', country)}
  autoFocus={true}
  disabled={false}
  countryPickerProps={{
    withFilter: true,
    withFlag: true,
    withCountryNameButton: true,
  }}
  theme={{
    containerStyle: styles.phoneContainer,
    textInputStyle: styles.input,
    flagButtonStyle: styles.flagButton,
    codeTextStyle: styles.codeText,
    dropDownImageStyle: styles.dropDownImage,
    enableDarkTheme: false,
  }}
  hideDropdownIcon={false}
  isCallingCodeEditable={false}
/>

Props

PropTypeDescriptionDefault
defaultValuesobjectDefault values for country code, calling code, and phone numberundefined
valuestringControlled value for the phone number inputundefined
onChangeText(text: string) => voidCallback when phone number changesundefined
onChangeCountry(country: Country) => voidCallback when selected country changesundefined
autoFocusbooleanAutomatically focuses the input when mountedfalse
disabledbooleanDisables the inputfalse
countryPickerPropsCountryPickerPropsProps for the country picker modal{}
maskInputPropsMaskInputPropsProps for the masked input component{}
themeThemeTheme configuration for styling the component{}
hideDropdownIconbooleanHides the dropdown arrow icon when set to truefalse
renderCustomDropdownReactNodeCustom component to replace the default dropdown arrowundefined
flagPropsobjectProps for customizing the country flag{}
dropDownImagePropsImagePropsProps for customizing the dropdown arrow image{}
isCallingCodeEditablebooleanControls whether the calling code can be editedtrue

Theme Properties

PropertyTypeDescriptionDefault
containerStyleStyleProp<ViewStyle>Style for the main containerundefined
textInputStyleStyleProp<TextStyle>Style for the text inputundefined
codeTextStyleStyleProp<TextStyle>Style for the calling code textundefined
flagButtonStyleStyleProp<ViewStyle>Style for the flag buttonundefined
dropDownImageStyleStyleProp<ImageStyle>Style for the dropdown arrow imageundefined
enableDarkThemebooleanEnables dark theme for the componentfalse

Utility Functions

isValidNumber(phoneNumber: string, countryCode: string): boolean

Validates a phone number for a specific country using Google's libphonenumber.

import { isValidNumber } from 'react-native-phone-entry';

const isValid = isValidNumber('+1234567890', 'US');

Dependencies

This library depends on the following packages:

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

TODO

  • Expose ref of the input
  • Add custom country picker modal

License

This project is licensed under the MIT License.

Made with create-react-native-library

Inspired by react-native-phone-number-input

Keywords

react-native

FAQs

Package last updated on 22 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts