Skip to main content

Basic Usage

The PhoneBox component is the easiest way to get started. It includes:

  • โœ… Country selection dropdown
  • โœ… Phone number formatting
  • โœ… Example-based placeholder
  • โœ… Mobile number validation (optional)

๐Ÿ“ฆ Importโ€‹

import { PhoneBox } from 'react-phonebox';
import 'react-phonebox/style.css';

๐Ÿš€ Exampleโ€‹

'use client';
import React, { useState } from 'react';
import { PhoneBox } from 'react-phonebox';
import 'react-phonebox/style.css';

export default function Example() {
const [value, setValue] = useState('');
const [raw, setRaw] = useState('');
const [valid, setValid] = useState(false);

return (
<PhoneBox
value={value}
onChange={setValue}
onRawChange={setRaw}
onValidChange={setValid}
initialCountry="US"
locale="en"
theme="dark"
searchPlaceholder="Search Country.."
mobileOnly={true}
/>
);
}

๐Ÿงพ Propsโ€‹

PropTypeDefaultDescription
valuestring""The formatted phone number
onChange(value: string) => voidโ€“Called on input change
onRawChange(raw: string) => voidโ€“Optional. Called with raw value including dial code
onValidChange(isValid: boolean) => voidโ€“Optional. Called with validation result
initialCountrystring (ISO2)"US"Default selected country
localestring"en"Used for localized country names
theme'dark' | 'light''dark'Input theme
searchPlaceholderstring'Search...'Placeholder for the country search field
mobileOnlybooleanfalseOnly allow mobile-type numbers