npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@laxkar77/react-native-country-code-input

v1.0.1

Published

A React Native country code input component with phone validation

Downloads

195

Readme

@laxkar77/react-native-country-code-input

A fully controlled React Native component for phone number input with country code selection, flag display, built-in phone validation, and full UI customization.

Installation

npm install @laxkar77/react-native-country-code-input

Basic Usage

import React, { useState } from 'react';
import { View } from 'react-native';
import { CountryCodeInput, countryData } from '@laxkar77/react-native-country-code-input';
import type { Country } from '@laxkar77/react-native-country-code-input';

export default function App() {
  const defaultCountry = countryData.find((c) => c.code === 'US')!;
  const [phone, setPhone] = useState('');
  const [country, setCountry] = useState<Country>(defaultCountry);

  return (
    <View style={{ padding: 20 }}>
      <CountryCodeInput
        value={phone}
        onChangeText={setPhone}
        selectedCountry={country}
        onSelectCountry={setCountry}
        label="Phone Number"
        placeholder="Enter phone number"
      />
    </View>
  );
}

Validation Example

import { validatePhone } from '@laxkar77/react-native-country-code-input';

const isValid = validatePhone(phone, country);
// true if phone matches the country's expected format

if (!isValid) {
  console.log('Invalid phone number for', country.name);
}

Format Phone

import { formatPhone } from '@laxkar77/react-native-country-code-input';

const full = formatPhone(country.dialCode, phone);
// e.g. "+14155551234"

Custom Styles

Use the styles prop to override any part of the component's appearance. Each key maps to a specific region of the UI.

import { CountryCodeInput } from '@laxkar77/react-native-country-code-input';
import type { CountryCodeInputStyles } from '@laxkar77/react-native-country-code-input';

const inputStyles: CountryCodeInputStyles = {
  inputWrapper: {
    borderColor: '#007AFF',
    borderRadius: 12,
    borderWidth: 2,
  },
  dialCodeText: {
    color: '#007AFF',
  },
  input: {
    color: '#1A1A1A',
    fontSize: 16,
  },
  errorText: {
    color: '#FF3B30',
    fontSize: 13,
  },
};

<CountryCodeInput
  value={phone}
  onChangeText={setPhone}
  selectedCountry={country}
  onSelectCountry={setCountry}
  styles={inputStyles}
/>

CountryCodeInputStyles keys

| Key | Type | Targets | | ---------------- | ----------- | -------------------------------------------- | | container | ViewStyle | Outer wrapper of the entire component | | label | TextStyle | Label text above the input | | inputWrapper | ViewStyle | The bordered row containing flag + input | | countrySection | ViewStyle | The flag + dial code + dropdown icon section | | dialCodeText | TextStyle | The dial code text (e.g. +1) | | input | TextStyle | The phone number TextInput | | errorText | TextStyle | Error message shown below the input |

Note: Flag rendering is always internal. Flags cannot be customized or hidden.

Custom Icons

Replace the default phone icon (☎) or dropdown arrow (▼) with any React node — your own icon component, an SVG, or an image.

import { Text } from 'react-native';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';

<CountryCodeInput
  value={phone}
  onChangeText={setPhone}
  selectedCountry={country}
  onSelectCountry={setCountry}
  renderPhoneIcon={() => (
    <MaterialIcons name="local-phone" size={20} color="#007AFF" style={{ marginRight: 8 }} />
  )}
  renderDropdownIcon={() => (
    <MaterialIcons name="keyboard-arrow-down" size={22} color="#333" />
  )}
/>

If either prop is omitted the default icon is used automatically — no visual change.

Props

| Prop | Type | Required | Default | Description | | -------------------- | ----------------------------- | -------- | ---------------- | -------------------------------------------------- | | value | string | Yes | — | Current phone number value | | onChangeText | (text: string) => void | Yes | — | Callback when the phone input changes | | selectedCountry | Country | Yes | — | Currently selected country object | | onSelectCountry | (country: Country) => void | Yes | — | Callback when a country is selected from the list | | errorMsg | string | No | — | Error message displayed below the input | | placeholder | string | No | Mobile number | TextInput placeholder text | | editable | boolean | No | true | Whether the phone input is editable | | label | string | No | — | Label text rendered above the input | | onSubmitEditing | () => void | No | — | Called when the keyboard submit button is pressed | | styles | CountryCodeInputStyles | No | — | Override styles for specific regions of the UI | | containerStyle | ViewStyle | No | — | Shorthand style override for the outer container | | labelStyle | TextStyle | No | — | Shorthand style override for the label text | | renderPhoneIcon | () => ReactNode | No | | Render a custom phone icon inside the input | | renderDropdownIcon | () => ReactNode | No | | Render a custom dropdown icon in the country area |

Country Object

interface Country {
  name: string;     // e.g. "United States"
  flag: string;     // emoji flag, e.g. "🇺🇸"
  dialCode: string; // e.g. "+1"
  code: string;     // ISO 3166-1 alpha-2, e.g. "US"
  regex: RegExp;    // validation pattern for this country's phone numbers
}

Exports

import {
  CountryCodeInput,   // The main component
  countryData,        // Array of all 239 countries
  validatePhone,      // (phone, country) => boolean
  formatPhone,        // (dialCode, phone) => string  e.g. "+919876543210"
} from '@laxkar77/react-native-country-code-input';

import type {
  Country,
  CountryCodeInputProps,
  CountryCodeInputStyles,
} from '@laxkar77/react-native-country-code-input';

License

MIT