Phone Input
Allows users to enter international phone numbers with automatic country flag detection, dial codes, and formatted digits.
8.1 KB
•Updated on September 5, 2026
We used the react-phone-number-input library to create this component.
Installation
Bash
pnpm dlx shadcn@latest add @spaceui/components-spaceui-phone-inputUsage
Code
import { PhoneInput } from '@/components/spaceui/phone-input'Code
<PhoneInput placeholder="Enter phone number" defaultCountry="US" value={value} onChange={setValue} />Examples
Size
API Reference
PhoneInput
The main component for entering phone numbers with country selection.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | - | The current phone number value in E.164 format. |
onChange | (value: string) => void | - | Callback fired when the value changes. |
variant | sm|default|lg | default | The vertical size of the input and country selector. |
popupClassName | string | - | Additional CSS classes for the country selection dropdown. |
defaultCountry | Country | - | The default country selected if no value is provided. |
placeholder | string | - | Placeholder text for the phone number input. |
className | string | - | Additional CSS classes for the root container. |
disabled | boolean | false | Whether the input and country selector are disabled. |
Utilities
The component re-exports essential phone number utilities:
Code
import {
PhoneInput,
isValidPhoneNumber,
formatPhoneNumber,
formatPhoneNumberIntl,
isPossiblePhoneNumber,
getCountryCallingCode,
} from '@/components/spaceui/phone-input'isValidPhoneNumber(value): Checks if the phone number is valid according to international metadata.formatPhoneNumber(value): Formats the phone number in national format.formatPhoneNumberIntl(value): Formats the phone number in international format (e.g.+1 213 373 4253).isPossiblePhoneNumber(value): Quick length check to see if the number could be possible.getCountryCallingCode(country): Returns the calling code for a given ISO country code (e.g.'FR'->'33').
External Props
This component also accepts all props from the react-phone-number-input library.
Examples
Large phone input
Disabled phone input
Phone input with preset value
Phone input with error state
Phone input with specific default country
Read-only phone input
Real-time validation
With Field, Label and Description
Keep in mind
- MIT License: Free and open-source for personal and commercial use. Feel free to copy, tweak, and adapt the components to match your exact needs.
- Credits & Inspiration: Some components on this site are inspired by or recreated from great ideas across the web. I'm not here to take credit; just to learn, experiment, and push interface craft further.
- Reach out & Claims: If an attribution was missed, or if you have any inquiry or claim, feel free to reach out directly on X to @adrielzimbril. I'll be glad to update or resolve it right away.
On This Page