PhoneInput
PhoneInput is a highly customizable component with auto formatting and validating the enterred phone number.
Install
To start using PhoneInput component, you can install the @react-awesome/phone-input
library or you can import it directly from @react-awesome/components
if you have installed it before. In your project directory, run
the following command to install the dependencies:
npm i @react-awesome/phone-input
Usage
Default
By default, Phone Input comes with a country selector.
- Ascension Island+247
- Andorra+376
- United Arab Emirates+971
- Afghanistan+93
- Antigua & Barbuda+1
- Anguilla+1
- Albania+355
- Armenia+374
- Angola+244
- Argentina+54
- American Samoa+1
- Austria+43
- Australia+61
- Aruba+297
- Åland Islands+358
- Azerbaijan+994
- Bosnia & Herzegovina+387
- Barbados+1
- Bangladesh+880
- Belgium+32
- Burkina Faso+226
- Bulgaria+359
- Bahrain+973
- Burundi+257
- Benin+229
- St. Barthélemy+590
- Bermuda+1
- Brunei+673
- Bolivia+591
- Caribbean Netherlands+599
- Brazil+55
- Bahamas+1
- Bhutan+975
- Botswana+267
- Belarus+375
- Belize+501
- Canada+1
- Cocos (Keeling) Islands+61
- Congo - Kinshasa+243
- Central African Republic+236
- Congo - Brazzaville+242
- Switzerland+41
- Côte d’Ivoire+225
- Cook Islands+682
- Chile+56
- Cameroon+237
- China+86
- Colombia+57
- Costa Rica+506
- Cuba+53
- Cape Verde+238
- Curaçao+599
- Christmas Island+61
- Cyprus+357
- Czechia+420
- Germany+49
- Djibouti+253
- Denmark+45
- Dominica+1
- Dominican Republic+1
- Algeria+213
- Ecuador+593
- Estonia+372
- Egypt+20
- Western Sahara+212
- Eritrea+291
- Spain+34
- Ethiopia+251
- Finland+358
- Fiji+679
- Falkland Islands+500
- Micronesia+691
- Faroe Islands+298
- France+33
- Gabon+241
- United Kingdom+44
- Grenada+1
- Georgia+995
- French Guiana+594
- Guernsey+44
- Ghana+233
- Gibraltar+350
- Greenland+299
- Gambia+220
- Guinea+224
- Guadeloupe+590
- Equatorial Guinea+240
- Greece+30
- Guatemala+502
- Guam+1
- Guinea-Bissau+245
- Guyana+592
- Hong Kong SAR China+852
- Honduras+504
- Croatia+385
- Haiti+509
- Hungary+36
- Indonesia+62
- Ireland+353
- Israel+972
- Isle of Man+44
- India+91
- British Indian Ocean Territory+246
- Iraq+964
- Iran+98
- Iceland+354
- Italy+39
- Jersey+44
- Jamaica+1
- Jordan+962
- Japan+81
- Kenya+254
- Kyrgyzstan+996
- Cambodia+855
- Kiribati+686
- Comoros+269
- St. Kitts & Nevis+1
- North Korea+850
- South Korea+82
- Kuwait+965
- Cayman Islands+1
- Kazakhstan+7
- Laos+856
- Lebanon+961
- St. Lucia+1
- Liechtenstein+423
- Sri Lanka+94
- Liberia+231
- Lesotho+266
- Lithuania+370
- Luxembourg+352
- Latvia+371
- Libya+218
- Morocco+212
- Monaco+377
- Moldova+373
- Montenegro+382
- St. Martin+590
- Madagascar+261
- Marshall Islands+692
- North Macedonia+389
- Mali+223
- Myanmar (Burma)+95
- Mongolia+976
- Macao SAR China+853
- Northern Mariana Islands+1
- Martinique+596
- Mauritania+222
- Montserrat+1
- Malta+356
- Mauritius+230
- Maldives+960
- Malawi+265
- Mexico+52
- Malaysia+60
- Mozambique+258
- Namibia+264
- New Caledonia+687
- Niger+227
- Norfolk Island+672
- Nigeria+234
- Nicaragua+505
- Netherlands+31
- Norway+47
- Nepal+977
- Nauru+674
- Niue+683
- New Zealand+64
- Oman+968
- Panama+507
- Peru+51
- French Polynesia+689
- Papua New Guinea+675
- Philippines+63
- Pakistan+92
- Poland+48
- St. Pierre & Miquelon+508
- Puerto Rico+1
- Palestinian Territories+970
- Portugal+351
- Palau+680
- Paraguay+595
- Qatar+974
- Réunion+262
- Romania+40
- Serbia+381
- Russia+7
- Rwanda+250
- Saudi Arabia+966
- Solomon Islands+677
- Seychelles+248
- Sudan+249
- Sweden+46
- Singapore+65
- St. Helena+290
- Slovenia+386
- Svalbard & Jan Mayen+47
- Slovakia+421
- Sierra Leone+232
- San Marino+378
- Senegal+221
- Somalia+252
- Suriname+597
- South Sudan+211
- São Tomé & Príncipe+239
- El Salvador+503
- Sint Maarten+1
- Syria+963
- Eswatini+268
- Tristan da Cunha+290
- Turks & Caicos Islands+1
- Chad+235
- Togo+228
- Thailand+66
- Tajikistan+992
- Tokelau+690
- Timor-Leste+670
- Turkmenistan+993
- Tunisia+216
- Tonga+676
- Türkiye+90
- Trinidad & Tobago+1
- Tuvalu+688
- Taiwan+886
- Tanzania+255
- Ukraine+380
- Uganda+256
- United States+1
- Uruguay+598
- Uzbekistan+998
- Vatican City+39
- St. Vincent & Grenadines+1
- Venezuela+58
- British Virgin Islands+1
- U.S. Virgin Islands+1
- Vietnam+84
- Vanuatu+678
- Wallis & Futuna+681
- Samoa+685
- Kosovo+383
- Yemen+967
- Mayotte+262
- South Africa+27
- Zambia+260
- Zimbabwe+263
onChange event
- 👉 isPossible
false
- 👉 isValid
false
- 👉 e164Value
- 👉 country
VN
- 👉 phoneCode
84
- 👉 formattedValue
- 👉 isSupported
true
import { PhoneInput } from '@react-awesome/phone-input'
import '@react-awesome/phone-input/dist/style.css'
const Example = () => {
return <PhoneInput />
}
Customizable Supported Countries
By default, Phone Input supports all countries but you can modify this behaviour to only support some specific countries by providing supportedCountries
property.
In this example, by passing ["US", "CA", "VN"]
to the supportedCountries
, you can only choose one of them in the country selector.
When users type in a phone number that belongs to an unsupported country, the onChange event will be triggered with the current selected country.
- Canada+1
- United States+1
- Vietnam+84
onChange event
- 👉 isPossible
false
- 👉 isValid
false
- 👉 e164Value
- 👉 country
VN
- 👉 phoneCode
84
- 👉 formattedValue
- 👉 isSupported
true
import { PhoneInput } from '@react-awesome/phone-input'
import '@react-awesome/phone-input/dist/style.css'
const Example = () => {
return <PhoneInput supportedCountries={['US', 'CA', 'VN']} />
}
Auto formating and validating with built-in caret handler
Phone Input automatically formats and validates every character that user type.
Try to type a random phone number and change some characters in the middle.
- Ascension Island+247
- Andorra+376
- United Arab Emirates+971
- Afghanistan+93
- Antigua & Barbuda+1
- Anguilla+1
- Albania+355
- Armenia+374
- Angola+244
- Argentina+54
- American Samoa+1
- Austria+43
- Australia+61
- Aruba+297
- Åland Islands+358
- Azerbaijan+994
- Bosnia & Herzegovina+387
- Barbados+1
- Bangladesh+880
- Belgium+32
- Burkina Faso+226
- Bulgaria+359
- Bahrain+973
- Burundi+257
- Benin+229
- St. Barthélemy+590
- Bermuda+1
- Brunei+673
- Bolivia+591
- Caribbean Netherlands+599
- Brazil+55
- Bahamas+1
- Bhutan+975
- Botswana+267
- Belarus+375
- Belize+501
- Canada+1
- Cocos (Keeling) Islands+61
- Congo - Kinshasa+243
- Central African Republic+236
- Congo - Brazzaville+242
- Switzerland+41
- Côte d’Ivoire+225
- Cook Islands+682
- Chile+56
- Cameroon+237
- China+86
- Colombia+57
- Costa Rica+506
- Cuba+53
- Cape Verde+238
- Curaçao+599
- Christmas Island+61
- Cyprus+357
- Czechia+420
- Germany+49
- Djibouti+253
- Denmark+45
- Dominica+1
- Dominican Republic+1
- Algeria+213
- Ecuador+593
- Estonia+372
- Egypt+20
- Western Sahara+212
- Eritrea+291
- Spain+34
- Ethiopia+251
- Finland+358
- Fiji+679
- Falkland Islands+500
- Micronesia+691
- Faroe Islands+298
- France+33
- Gabon+241
- United Kingdom+44
- Grenada+1
- Georgia+995
- French Guiana+594
- Guernsey+44
- Ghana+233
- Gibraltar+350
- Greenland+299
- Gambia+220
- Guinea+224
- Guadeloupe+590
- Equatorial Guinea+240
- Greece+30
- Guatemala+502
- Guam+1
- Guinea-Bissau+245
- Guyana+592
- Hong Kong SAR China+852
- Honduras+504
- Croatia+385
- Haiti+509
- Hungary+36
- Indonesia+62
- Ireland+353
- Israel+972
- Isle of Man+44
- India+91
- British Indian Ocean Territory+246
- Iraq+964
- Iran+98
- Iceland+354
- Italy+39
- Jersey+44
- Jamaica+1
- Jordan+962
- Japan+81
- Kenya+254
- Kyrgyzstan+996
- Cambodia+855
- Kiribati+686
- Comoros+269
- St. Kitts & Nevis+1
- North Korea+850
- South Korea+82
- Kuwait+965
- Cayman Islands+1
- Kazakhstan+7
- Laos+856
- Lebanon+961
- St. Lucia+1
- Liechtenstein+423
- Sri Lanka+94
- Liberia+231
- Lesotho+266
- Lithuania+370
- Luxembourg+352
- Latvia+371
- Libya+218
- Morocco+212
- Monaco+377
- Moldova+373
- Montenegro+382
- St. Martin+590
- Madagascar+261
- Marshall Islands+692
- North Macedonia+389
- Mali+223
- Myanmar (Burma)+95
- Mongolia+976
- Macao SAR China+853
- Northern Mariana Islands+1
- Martinique+596
- Mauritania+222
- Montserrat+1
- Malta+356
- Mauritius+230
- Maldives+960
- Malawi+265
- Mexico+52
- Malaysia+60
- Mozambique+258
- Namibia+264
- New Caledonia+687
- Niger+227
- Norfolk Island+672
- Nigeria+234
- Nicaragua+505
- Netherlands+31
- Norway+47
- Nepal+977
- Nauru+674
- Niue+683
- New Zealand+64
- Oman+968
- Panama+507
- Peru+51
- French Polynesia+689
- Papua New Guinea+675
- Philippines+63
- Pakistan+92
- Poland+48
- St. Pierre & Miquelon+508
- Puerto Rico+1
- Palestinian Territories+970
- Portugal+351
- Palau+680
- Paraguay+595
- Qatar+974
- Réunion+262
- Romania+40
- Serbia+381
- Russia+7
- Rwanda+250
- Saudi Arabia+966
- Solomon Islands+677
- Seychelles+248
- Sudan+249
- Sweden+46
- Singapore+65
- St. Helena+290
- Slovenia+386
- Svalbard & Jan Mayen+47
- Slovakia+421
- Sierra Leone+232
- San Marino+378
- Senegal+221
- Somalia+252
- Suriname+597
- South Sudan+211
- São Tomé & Príncipe+239
- El Salvador+503
- Sint Maarten+1
- Syria+963
- Eswatini+268
- Tristan da Cunha+290
- Turks & Caicos Islands+1
- Chad+235
- Togo+228
- Thailand+66
- Tajikistan+992
- Tokelau+690
- Timor-Leste+670
- Turkmenistan+993
- Tunisia+216
- Tonga+676
- Türkiye+90
- Trinidad & Tobago+1
- Tuvalu+688
- Taiwan+886
- Tanzania+255
- Ukraine+380
- Uganda+256
- United States+1
- Uruguay+598
- Uzbekistan+998
- Vatican City+39
- St. Vincent & Grenadines+1
- Venezuela+58
- British Virgin Islands+1
- U.S. Virgin Islands+1
- Vietnam+84
- Vanuatu+678
- Wallis & Futuna+681
- Samoa+685
- Kosovo+383
- Yemen+967
- Mayotte+262
- South Africa+27
- Zambia+260
- Zimbabwe+263
onChange event
- 👉 isPossible
false
- 👉 isValid
false
- 👉 e164Value
- 👉 country
VN
- 👉 phoneCode
84
- 👉 formattedValue
- 👉 isSupported
true
import { PhoneInput } from '@react-awesome/phone-input'
import '@react-awesome/phone-input/dist/style.css'
const Example = () => {
return <PhoneInput />
}
Without country select
Phone Input without country select.
onChange event
- 👉 isPossible
false
- 👉 isValid
false
- 👉 e164Value
- 👉 country
VN
- 👉 phoneCode
84
- 👉 formattedValue
- 👉 isSupported
true
import { PhoneInput } from '@react-awesome/phone-input'
import '@react-awesome/phone-input/dist/style.css'
const Example = () => {
return <PhoneInput showCountrySelect={false} />
}
API
PhoneInput components takes the following props:
className
(optional)
Classes for the container.
- Type:
string
- Default:
undefined
inputClassname
(optional)
Classes for the input.
- Type:
string
- Default:
undefined
selectClassname
(optional)
Classes for the country select container.
- Type:
string
- Default:
undefined
selectButtonClassname
(optional)
Classes for the country select button.
- Type:
string
- Default:
undefined
selectListClassname
(optional)
Classes for the country select pane.
- Type:
string
- Default:
undefined
selectOptionClassname
(optional)
Classes for each country select option.
- Type:
string
- Default:
undefined
PhoneInput also takes usePhoneInput props.
All other props will be passed through to the input element.