Socket
Book a DemoInstallSign in
Socket

phone-input-lib

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

phone-input-lib

A lightweight, developer-friendly npm library that provides a phone number input component with flags, country codes, and Tailwind support.

latest
Source
npmnpm
Version
1.1.1
Version published
Weekly downloads
9
-94.34%
Maintainers
1
Weekly downloads
 
Created
Source

Phone Input Library

A lightweight, developer-friendly npm library that provides a phone number input component with flags, country codes, and Tailwind support.

Compatibility Note

This library is compatible with React 16.8+ and has been tested with multiple React versions to ensure broad compatibility.

Features

  • 🌍 Country selector with flags and dial codes
  • ✅ Phone number validation using libphonenumber-js
  • 🎨 TailwindCSS compatible - pass your own classes
  • 📦 Lightweight - only essential dependencies
  • ⌨️ TypeScript support - fully typed components and hooks
  • 🌐 International formatting support

Installation

npm install phone-input-lib

Usage

Basic Usage

import { PhoneInput } from 'phone-input-lib';

function MyComponent() {
  const [phone, setPhone] = useState('');

  return <PhoneInput value={phone} onChange={setPhone} />;
}

With TailwindCSS Styling

import { PhoneInput } from 'phone-input-lib';

function MyComponent() {
  const [phone, setPhone] = useState('');

  return (
    <PhoneInput
      value={phone}
      onChange={setPhone}
      className="flex gap-2 items-center"
      inputClassName="border p-2 rounded"
      selectClassName="p-2"
    />
  );
}

Without Flags

import { PhoneInput } from 'phone-input-lib';

function MyComponent() {
  const [phone, setPhone] = useState('');

  return <PhoneInput value={phone} onChange={setPhone} showFlags={false} />;
}

API

PhoneInput Props

PropTypeDefaultDescription
valuestring''The phone number value
onChange(value: string) => voidrequiredCallback when phone number changes
defaultCountrystring'us'Default selected country ISO code
classNamestring''CSS class for the container
inputClassNamestring''CSS class for the input field
selectClassNamestring''CSS class for the country select
showFlagsbooleantrueWhether to show country flags
disabledbooleanfalseWhether the input is disabled
placeholderstring'Phone number'Input placeholder text
requiredbooleanfalseWhether the input is required
errorbooleanfalseWhether to show error state

Returns an object with:

  • isValid: boolean - whether the phone number is valid
  • formattedValue: string - formatted phone number
  • nationalFormat: string - national format of the phone number
  • internationalFormat: string - international format of the phone number
  • e164Format: string - E.164 format of the phone number
  • countryCode: string - detected country code

Components

CountrySelect

A standalone country selector component.

import { CountrySelect } from 'phone-input-lib';

function MyComponent() {
  const [country, setCountry] = useState('us');

  return (
    <CountrySelect
      value={country}
      onChange={setCountry}
      className="p-2 border rounded"
    />
  );
}

FlagIcon

A standalone flag icon component.

import { FlagIcon } from 'phone-input-lib';

function MyComponent() {
  return <FlagIcon country={countryData} className="mr-2" />;
}

License

MIT

Keywords

phone

FAQs

Package last updated on 16 Sep 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