React Phone Number Input

3.4.16 · active · verified Tue Apr 21

react-phone-number-input is a comprehensive React component designed for entering and formatting international telephone numbers. It leverages the robust `libphonenumber-js` library internally for accurate parsing, validation, and formatting, ensuring numbers are consistently output in the E.164 format (e.g., "+12133734253"). The package is currently at version 3.4.16 and demonstrates an active release cadence, indicating ongoing development and maintenance. Its key differentiators include offering both a full-featured input with an international country select dropdown and a basic input-only variant, alongside native UI integration for country selection on mobile devices. The component effectively handles diverse country codes, various number formats, and provides clear mechanisms for controlling default country selections and managing input changes via its props.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a functional React component using the default `PhoneInput` (with country select). It shows how to manage the input's value using React state and displays the resulting E.164 formatted number, including necessary CSS import and default country setting.

import React, { useState } from 'react';
import 'react-phone-number-input/style.css';
import PhoneInput from 'react-phone-number-input';

function App() {
  const [value, setValue] = useState();

  // `value` will be the parsed phone number in E.164 format (e.g., "+12133734253").
  // For an empty input, `value` will be `undefined`.
  return (
    <div style={{ maxWidth: '400px', margin: '50px auto', fontFamily: 'sans-serif' }}>
      <h1>International Phone Input</h1>
      <p>Enter your phone number below:</p>
      <PhoneInput
        placeholder="Enter phone number"
        value={value}
        onChange={setValue}
        defaultCountry="US"
        international
        countryCallingCodeEditable={false}
      />
      {value && <p>Parsed E.164 Value: <code>{value}</code></p>}
      {!value && <p>Input is currently empty or invalid.</p>}
    </div>
  );
}

export default App;

view raw JSON →