
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@quantfive/react-phone-input-2
Advanced tools
Highly customizable phone input component with auto formatting.

npm install react-phone-input-2 --save
import PhoneInput from 'react-phone-input-2'
import 'react-phone-input-2/lib/style.css'
<PhoneInput
country={'us'}
value={this.state.phone}
onChange={phone => this.setState({ phone })}
/>
available styles - style • high-res • material • bootstrap • semantic-ui • plain

| Name | Type | Description | Example |
|---|---|---|---|
| country | string | initial country | 'us' | 1 |
| value | string | input state value | |
| onlyCountries | array | country codes to be included | ['cu','cw','kz'] |
| preferredCountries | array | country codes to be at the top | ['cu','cw','kz'] |
| excludeCountries | array | array of country codes to be excluded | ['cu','cw','kz'] |
| placeholder | string | custom placeholder | |
| searchPlaceholder | string | custom search placeholder | |
| inputProps | object | props to pass into the input |
| Booleans | Default | Description |
|---|---|---|
| autoFormat | true | on/off phone formatting |
| disabled | false | disable input and dropdown |
| disableDropdown | false | disable dropdown only |
| disableCountryCode | false | |
| enableAreaCodes | false | enable local codes for all countries |
| enableLongNumbers | false | |
| countryCodeEditable | true | |
| enableSearch | false | enable search in the dropdown |
| disableSearchIcon | false | hide icon for the search field |
<PhoneInput
inputProps={{
name: 'phone',
required: true,
autoFocus: true
}}
/>
| containerClass | string | class for container |
| inputClass | string | class for input |
| buttonClass | string | class for dropdown button |
| dropdownClass | string | class for dropdown container |
| searchClass | string | class for search field |
| containerStyle | object | styles for container |
| inputStyle | object | styles for input |
| buttonStyle | object | styles for dropdown button |
| dropdownStyle | object | styles for dropdown container |
| searchStyle | object | styles for search field |
| onChange | onFocus | onBlur | onClick | onKeyDown |
Country data object not returns from onKeyDown event
| Data | Type | Description |
|---|---|---|
| value/event | string/object | event or the phone number |
| country data | object | country object { name, dialCode, countryCode (iso2) } |
| Name | Type | Description |
|---|---|---|
| regions | array/string | to show countries only from specified regions |
| Regions |
|---|
| ['america', 'europe', 'asia', 'oceania', 'africa'] |
| Subregions |
| ['north-america', 'south-america', 'central-america', 'carribean', 'eu-union', 'ex-ussr', 'ex-yugos', 'baltic', 'middle-east', 'north-africa'] |
<PhoneInput
country='de'
regions={'europe'}
/>
<PhoneInput
country='us'
regions={['north-america', 'carribean']}
/>
es Spanish, de Deutsch, ru Russian, fr French
jp Japanese, cn Chinese, pt Portuguese, it Italian
ir Iranian, ar Arabic, id Indonesian
import es from 'react-phone-input-2/lang/es.json'
<PhoneInput
localization={es}
/>
<PhoneInput
enableAreaCodes={true}
enableAreaCodes={['us', 'ca']}
/>
<PhoneInput
onlyCountries={['fr', 'at']}
masks={{fr: '+.. (...) ..-..-..', at: '+.. (....) ...-....'}}
/>
<PhoneInput
onlyCountries={['gr', 'fr', 'us']}
areaCodes={{gr: ['2694', '2647'], fr: ['369', '463'], us: ['300']}}
/>
| defaultMask | ...... ...... .. |
| prefix | + |
| copyNumbersOnly | true |
| renderStringAsFlag | string |
| autocompleteSearch | false |
| jumpCursorToEnd | false |
<PhoneInput
onlyCountries={['de', 'es']}
localization={{de: 'Deutschland', es: 'España'}}
/>
<PhoneInput
onlyCountries={['de', 'es']}
localization={{'Germany': 'Deutschland', 'Spain': 'España'}}
/>
<PhoneInput
onlyCountries={['fr', 'at']}
preserveOrder={['onlyCountries', 'preferredCountries']}
/>
handleOnChange(value, data, event) {
this.setState({ rawPhone: value.replace(/[^0-9]+/g,'').slice(data.dialCode.length) })
}
<PhoneInput
isValid={(inputNumber, onlyCountries) => {
return onlyCountries.some((country) => {
return startsWith(inputNumber, country.dialCode) || startsWith(country.dialCode, inputNumber);
});
}}
/>
<script src="https://unpkg.com/react-phone-input-2@2.x/dist/lib.js"></script>
Code style changes not allowed
Based on react-phone-input
FAQs
A react component to format phone numbers
We found that @quantfive/react-phone-input-2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.