Skip to Content
Urban Cowboy
Components

Phone Input

International phone field with country selection, formatting and E.164 validation.

PhoneInput parses the initial value into a country and national number, formats input as it is typed and reports the E.164 value with a validity flag. The docs harness shows the reported value locally; it never submits a guest form.

*
string
*
string
*
boolean
*
boolean

Invalid state

*
string
*
string
*
boolean
*
boolean

Props

PropValuesNotes
valueE.164 stringControlled value
defaultCountryISO codeUsed when value has no country; defaults to US
onChange(e164, valid) => voidReports the normalised value and validity
required, invalidbooleanNative required attribute and error styling
id, name, ariaDescribedBystringForm wiring and accessible description

Accessibility

The country selector and number field are labelled separately, and the invalid state is exposed through aria-invalid so assistive technology announces the error.

Responsive behaviour

The country flag and dial code keep a fixed width while the number field flexes, so no layout shift occurs when switching countries on a narrow screen.

Usage

import { PhoneInput } from '@/components/forms/phone-input';

<PhoneInput
  value={phone}
  defaultCountry="US"
  onChange={(e164, valid) => {
    setPhone(e164);
    setValid(valid);
  }}
/>

View source