Highly customizable phone input component with auto formatting.
npm install react-phone-input-2 --save
React.render(
<ReactPhoneInput defaultCountry={'us'} onChange={handleOnChange}/>,
document.getElementById('root')
);
Your handler for the onChange
event should expect a string as
parameter, where the value is that of the entered phone number. For example:
function handleOnChange(value) {
this.setState({
phone: value
});
}
Name | Type | Description | Example |
---|---|---|---|
excludeCountries | array | array of country codes to be excluded | ['cu','cw','kz'] |
onlyCountries | array | country codes to be included | ['cu','cw','kz'] |
preferredCountries | array | country codes to be at the top | ['cu','cw','kz'] |
defaultCountry | string | initial country | 'us' |
value | string | initial phone value | |
placeholder | string | custom placeholder | |
inputStyle | object | styles for input | |
buttonStyle | object | styles for dropdown button | |
dropdownStyle | object | styles for countries container | |
autoFormat | bool | on/off auto formatting (on by default) | |
disabled | bool | disable input and dropdown | |
disableAreaCodes | bool | disable local codes for all countries |
You can specify custom regions use string or array of strings.
Regions |
---|
['america', 'europe', 'asia', 'oceania', 'africa'] |
Subregions (used region property too) |
['north-america', 'south-america', 'central-america', 'carribean', 'european-union', 'ex-ussr', 'middle-east', 'north-africa'] |
Region selected: {'europe'}
<ReactPhoneInput
defaultCountry='it'
regions={'europe'}
/>
Regions selected: {['north-america', 'carribean']}
<ReactPhoneInput
defaultCountry='ca'
regions={['north-america', 'carribean']}
/>
onChange | onFocus | onBlur | onClick | onKeyDown |
Based on react-phone-input using MIT