Gathering detailed insights and metrics for react-phone-input-2
Gathering detailed insights and metrics for react-phone-input-2
Gathering detailed insights and metrics for react-phone-input-2
Gathering detailed insights and metrics for react-phone-input-2
📞 Highly customizable phone input component with auto formatting
npm install react-phone-input-2
83.4
Supply Chain
93
Quality
75.2
Maintenance
100
Vulnerability
98.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
957 Stars
375 Commits
543 Forks
8 Watching
1 Branches
71 Contributors
Updated on 27 Nov 2024
Minified
Minified + Gzipped
JavaScript (67.15%)
Less (32.53%)
HTML (0.32%)
Cumulative downloads
Total Downloads
Last day
-5.3%
71,715
Compared to previous day
Last week
-0.4%
368,521
Compared to previous week
Last month
9%
1,564,764
Compared to previous month
Last year
17.2%
16,737,346
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.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 23/30 approved changesets -- score normalized to 7
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Morematerial-ui-phone-number
A material-ui react component to format phone numbers. Based on react-phone-input-2
react-phone-input-material-ui
A material-ui react component to format phone numbers. Based on react-phone-input-2
mui-phone-number
A material-ui v5+ react component to format phone numbers. Based on react-phone-input-2
react-phone-input-international
A react component to format phone numbers. Fork from https://github.com/bl00mber/react-phone-input-2