Gathering detailed insights and metrics for react-phone-input-2-pcf
Gathering detailed insights and metrics for react-phone-input-2-pcf
Gathering detailed insights and metrics for react-phone-input-2-pcf
Gathering detailed insights and metrics for react-phone-input-2-pcf
📞 Highly customizable phone input component with auto formatting
npm install react-phone-input-2-pcf
Typescript
Module System
Node Version
NPM Version
63.7
Supply Chain
92.8
Quality
84.3
Maintenance
100
Vulnerability
98.6
License
JavaScript (67.15%)
Less (32.53%)
HTML (0.32%)
Total Downloads
2,117
Last Day
6
Last Week
6
Last Month
103
Last Year
2,117
MIT License
1,001 Stars
375 Commits
548 Forks
7 Watchers
1 Branches
70 Contributors
Updated on Jul 17, 2025
Latest Version
1.0.25
Package Id
react-phone-input-2-pcf@1.0.25
Unpacked Size
1.16 MB
Size
409.14 kB
File Count
28
NPM Version
8.15.0
Node Version
16.17.0
Published on
Sep 05, 2024
Cumulative downloads
Total Downloads
Last Day
0%
6
Compared to previous day
Last Week
200%
6
Compared to previous week
Last Month
1,616.7%
103
Compared to previous month
Last Year
0%
2,117
Compared to previous year
Highly customizable phone input component with auto formatting.
1npm install react-phone-input-2 --save
1import PhoneInput from 'react-phone-input-2' 2import 'react-phone-input-2/lib/style.css' 3 4<PhoneInput 5 country={'us'} 6 value={this.state.phone} 7 onChange={phone => this.setState({ phone })} 8/>
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 | |
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 |
enableTerritories | false | enable dependent territories with population of ~100,000 or lower |
enableLongNumbers | false | boolean/number |
countryCodeEditable | true | |
enableSearch | false | enable search in the dropdown |
disableSearchIcon | false | hide icon for the search field |
1<PhoneInput 2 inputProps={{ 3 name: 'phone', 4 required: true, 5 autoFocus: true 6 }} 7/>
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 |
onChange(value, country, e, formattedValue)
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'] |
1<PhoneInput 2 country='de' 3 regions={'europe'} 4/> 5 6<PhoneInput 7 country='us' 8 regions={['north-america', 'carribean']} 9/>
es
Spanish, de
Deutsch, ru
Russian, fr
French
jp
Japanese, cn
Chinese, pt
Portuguese, it
Italian
ir
Iranian, ar
Arabic, tr
Turkish, id
Indonesian
hu
Hungarian, pl
Polish, ko
Korean
1import es from 'react-phone-input-2/lang/es.json' 2 3<PhoneInput 4 localization={es} 5/>
1<PhoneInput 2 enableAreaCodes={true} 3 enableAreaCodes={['us', 'ca']} 4 enableAreaCodeStretch 5/>
If enableAreaCodeStretch
is added, the part of the mask with the area code will not stretch to length of the respective section of phone mask.
Example: +61 (2), +61 (02)
1<PhoneInput 2 onlyCountries={['fr', 'at']} 3 masks={{fr: '(...) ..-..-..', at: '(....) ...-....'}} 4/>
1<PhoneInput 2 onlyCountries={['gr', 'fr', 'us']} 3 areaCodes={{gr: ['2694', '2647'], fr: ['369', '463'], us: ['300']}} 4/>
defaultMask | ... ... ... ... .. |
alwaysDefaultMask | false |
prefix | + |
searchPlaceholder | 'search' |
searchNotFound | 'No entries to show' |
copyNumbersOnly | true |
renderStringAsFlag | string |
autocompleteSearch | false |
jumpCursorToEnd | false |
priority | {{ca: 0, us: 1, kz: 0, ru: 1}} |
enableClickOutside | true |
showDropdown | false |
defaultErrorMessage | string |
specialLabel | string |
disableInitialCountryGuess | false |
disableCountryGuess | false |
1<PhoneInput 2 onlyCountries={['de', 'es']} 3 localization={{de: 'Deutschland', es: 'España'}} 4/> 5 6<PhoneInput 7 onlyCountries={['de', 'es']} 8 localization={{'Germany': 'Deutschland', 'Spain': 'España'}} 9/>
1<PhoneInput 2 onlyCountries={['fr', 'at']} 3 preserveOrder={['onlyCountries', 'preferredCountries']} 4/>
1handleOnChange(value, data, event, formattedValue) {
2 this.setState({ rawPhone: value.slice(data.dialCode.length) })
3}
isValid(value, country, countries, hiddenAreaCodes)
1<PhoneInput 2 isValid={(value, country) => { 3 if (value.match(/12345/)) { 4 return 'Invalid value: '+value+', '+country.name; 5 } else if (value.match(/1234/)) { 6 return false; 7 } else { 8 return true; 9 } 10 }} 11/>
1import startsWith from 'lodash.startswith'; 2 3<PhoneInput 4 isValid={(inputNumber, country, countries) => { 5 return countries.some((country) => { 6 return startsWith(inputNumber, country.dialCode) || startsWith(country.dialCode, inputNumber); 7 }); 8 }} 9/>
To clear country
, pass null
as value
.
1const phoneCountryFormat = useMemo(() => phoneCountry?.format || undefined, [phoneCountry]); 2const placeholder = useMemo(() => { 3 if (phoneCountryFormat) { 4 const words = phoneCountryFormat.split(' '); 5 words.shift(); // I'm using only local numbers so here I remove the country code from the format 6 let text = words.join(' '); 7 // first digit is special on french numbers, these 3 lines could be removed 8 if (country === 'fr') { 9 text = text.replace('.', '6'); 10 } 11 while (text.indexOf('.') > -1) { 12 text = text.replace('.', `${Math.min(9, Math.max(1, Math.floor(Math.random() * 10)))}`); 13 } 14 return text; 15 } 16 return ''; 17}, [phoneCountryFormat, country]);
1<script src="https://unpkg.com/react-phone-input-2@2.x/dist/lib.js"></script>
Based on react-phone-input
No vulnerabilities found.