Phone Input with Validation
Same country picker and flags as Phone Input, plus national formatting, per-country validation, and onValidationChange for form gating. Digits are kept when the country changes.
Live status
onValidationChange drives the hint below — try an invalid US number and blur to see the error border.
Loading…
Installation
CLI
Also needs
npx @sonojs/ui@latest add dialog input input-group phone-input popover tablenpm i libphonenumber-js lucide-reactUsage
phone-input-validation.tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| defaultCountry | string | "US" | Initial ISO2 country code when uncontrolled. |
| country | string | - | Controlled ISO2 country code. |
| onCountryChange | (country: PhoneCountry) => void | - | Fires when the selected country changes. |
| value | string | - | Controlled national number (formatted or digits; sanitized internally). |
| defaultValue | string | "" | Initial national number when uncontrolled. |
| onChange | (value: string) => void | - | Fires with the formatted national number. |
| onValueChange | (payload) => void | - | Formatted national, raw digits, validation state, and optional E.164 when valid. |
| onValidationChange | (state: "empty" · "incomplete" · "valid" · "invalid") => void | - | Fires whenever the validation state changes. |
| invalid | boolean | - | Force invalid styling regardless of derived state. |
| showFlag | boolean | true | When `false`, hides flag images and shows dial codes only. |
| flagCdnBase | string | SonoJS flags CDN | CDN base for flag SVGs (no trailing slash). |
| disabled | boolean | false | Disables the country picker and input. |
| className | string | - | Merge Tailwind classes on the input group root. |