UIGetting StartedPhone Input

Phone Input

A flexible phone number input with international support, validation, and optional country selector.

The PhoneInput component provides a user-friendly way to enter and validate phone numbers, with built-in support for international formats and country selection. It enhances UX by handling formatting, validation, and country code selection automatically.

By default, this component includes a country selector. You can control its visibility using the withCountryCodeSelector prop.

Current Value:

Installation

pnpm dlx shadcn@latest add https://shaddy-docs.vercel.app/r/phone-input

With default country

Current Value:

Without Country Selector

Current Value:

Usage

<PhoneInput
  onCountryChange={(data) => console.log("Country changed:", data)}
  onPhoneChange={(phone) => console.log("Phone changed:", phone)}
  defaultCountry="United_States"
  withCountryCodeSelector
/>

Props

PropTypeDescription
onCountryChange(data: CountryData | undefined) => voidCallback when the country selection changes.
onPhoneChange(phone: string) => voidCallback when the phone number changes.
defaultCountrykeyof typeof CountryAlpha2Sets the default selected country (using its alpha-2 code).
withCountryCodeSelectorbooleanShow or hide the country code selector (default: true).

Other common input props like placeholder, value, className, and disabled are also supported.