PX-UI
Components

Phone Input

An international phone number input with country selector, formatting, and validation using E.164 format

Overview

The PhoneInput component provides an international phone number input with a country selector dropdown. It automatically validates and formats phone numbers into E.164 format using google-libphonenumber, and shows inline error feedback for invalid numbers.

Import

import { PhoneInput } from "@px-ui/forms";

Usage

Phone

Value: +919600300630

import { useState } from "react";
import { PhoneInput } from "@px-ui/forms";

function Example() {
  const [phone, setPhone] = useState("");

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

Examples

Default Country

Use the country prop to set the default selected country. Accepts ISO 3166-1 alpha-2 codes (lowercase).

Phone
Phone
Phone
<PhoneInput value={phone} onChange={setPhone} country="us" />
<PhoneInput value={phone} onChange={setPhone} country="gb" />
<PhoneInput value={phone} onChange={setPhone} country="in" />

Validation

PhoneInput has built-in validation powered by google-libphonenumber. Invalid numbers display an error message and red styling. You can also force the error state externally via the error prop.

Phone

Type an incomplete number to see validation feedback.

Phone

Please enter a valid phone number for this region.

{/* Built-in validation */}
<PhoneInput value={phone} onChange={setPhone} />

{/* External error state */}
<PhoneInput value={phone} onChange={setPhone} error />

Disabled

Phone
<PhoneInput value="+14155552671" onChange={() => {}} disabled />

API Reference

PhoneInput

PropTypeDefaultDescription
valuestring-The phone number value (E.164 format when valid)
onChange(value: string) => void-Callback fired when the value changes
countrystring"us"Default country code (ISO 3166-1 alpha-2, lowercase)
errorbooleanfalseForces error styling regardless of validation state
placeholderstring-Placeholder text for the input
disabledbooleanfalseDisables the input
classNamestring-Additional CSS classes for the wrapper

Notes

  • Valid phone numbers are automatically formatted to E.164 (e.g., +14155552671).
  • Invalid numbers pass through the raw input string to onChange.
  • The country dropdown allows users to switch countries at any time; validation adjusts to the selected region.