
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-universal-phone
Advanced tools
A lightweight, customizable, multi-language phone input component for React.
A lightweight, customizable, multi-language phone input component for React.
Install react-universal-phone with npm.
npm install react-universal-phone
or
yarn add react-universal-phone
import { PhoneInput } from "react-universal-phone";
function App() {
return <PhoneInput />;
}
export default App;
/** Using Hindi as display language */
<PhoneInput locale="hi" />
/** Default supported languages :-
* en, hi, bn, gu, kn, ml, mr, pa, ta, te, ja, de, th, ru
*/
| Parameter | Type | Description |
|---|---|---|
optionsFormat 🔗 | string | Manage the format of dropdown country options. |
addCountries 🔗 | Country[] | Add missing countries by providing an array of country objects. |
removeCountries 🔗 | string[] | Remove countries from the options by providing an array of country codes. |
defaultOpenOptions 🔗 | boolean | Keep the options dropdown open by default. |
dialCodeSelectionFormat 🔗 | string | Change the format of selected option at the top. |
closeOnOutsideClick 🔗 | boolean | Close the options dropdown when clicking outside. |
onChange 🔗 | Function | A function that listens for changes. |
outputSchema 🔗 | object | Define which country details should be included in the output. |
defaultCountry 🔗 | string or boolean | To select a default country. |
dialCodePlaceholder 🔗 | string or boolean | Set or disable the dial code placeholder. |
numberPlaceholder 🔗 | string or boolean | Set or disable the main number placeholder. |
dropdownArrow 🔗 | string or boolean | Change or disable the down arrow icon. |
divider 🔗 | boolean | Enable/Disable the divider between the dial code & main input |
focusOnMainInputAfterClose 🔗 | boolean | Focus on the main number input just after close the options dropdown. |
parentClass 🔗 | string | Add parent classes on the root element. Multiple also allowed, space separated. |
labelClass 🔗 | string | Add classes on the label element. Multiple also allowed, space separated. |
mainInputClass 🔗 | string | Add classes on the main input element. Multiple also allowed, space separated. |
optionsContainerClass 🔗 | string | Add classes on the root element of options dropdown. Multiple also allowed, space separated. |
dialCodeContainerClass 🔗 | string | Add classes on the dial code container element. Multiple also allowed, space separated. |
onMainInputFocus 🔗 | Function | A function to listen for focus events. |
onMainInputBlur 🔗 | Function | A function to listen for blur events. |
onOpenMenu 🔗 | Function | A function triggered when open the options dropdown. |
onCloseMenu 🔗 | Function | A function triggered when close the options dropdown. |
label 🔗 | boolean | Show/Hide label. |
labelText 🔗 | string | Set custom text for the label. |
labelType 🔗 | string | default, fixed_floating To change the label view. |
masking 🔗 | boolean | Enable/Disable masking for the main number input. |
maskingFormat 🔗 | string | To change adjust the masking format. |
validateMasking 🔗 | boolean | This will allow typing only till the masking format. |
locale 🔗 | string | Change the language for the input completely. |
fallbackLanguage 🔗 | string | A fallback language if any translation is not available in any particular language. |
addOrReplaceLocale 🔗 | LocaleTypes | To add some new or replace existing language translations. |
config | object | To add a global configuration. Most of the props are allowed here in the config object. |
value 🔗 | string or object | Value to set the input. |
id 🔗 | string | Input ID. |
name 🔗 | string | Input name. |
/** Default value is FLAG-CODE-NAME-DIALCODE */
/** Customize the view of options dropdown using this prop.
* "FLAG-CODE-NAME-DIALCODE" these are all the possible values for this. We can change the order of any item.
*/
/** Example 1 :- */
<PhoneInput config={{
optionsFormat:"FLAG-NAME"
}} />
/** Example 2 :- */
<PhoneInput optionsFormat="FLAG-NAME-DIALCODE" />
/** Add a new country if not available by default. */
/** Example 1 :- */
<PhoneInput config={{
addCountries:[
{
name: "New country name",
code: "EXNC",
dialCode: "+687",
flag: "🧩"
}
]
}} />
/** Example 2 :- */
<PhoneInput addCountries={[
{
name: "New country name",
code: "EXNC",
dialCode: "+687",
flag: "🧩"
}
]} />
/** Remove specific countries if you don’t want. Just need to provide countryCodes */
/** Example 1 :- */
<PhoneInput config={{
removeCountries:["AD", "AE", "PK"]
}} />
/** Example 2 :- */
<PhoneInput removeCountries={["AD", "AE", "PK"]} />
/** Keep the options dropdown open by default. */
/** Example 1 :- */
<PhoneInput config={{
defaultOpenOptions:true
}} />
/** Example 2 :- */
<PhoneInput defaultOpenOptions={true} />
/** Default value is FLAG-DIALCODE */
/** We can pick any one or all from FLAG-CODE-NAME-DIALCODE */
/** Example 1 :- */
<PhoneInput config={{
dialCodeSelectionFormat:"FLAG"
}} />
/** Example 2 :- */
<PhoneInput dialCodeSelectionFormat={"FLAG-NAME"} />
/** Default value is true */
/** Example 1 :- */
<PhoneInput config={{
closeOnOutsideClick:false
}} />
/** Example 2 :- */
<PhoneInput closeOnOutsideClick={false} />
/** Adding a listener function to get the value. */
/** Example 1 :- */
<PhoneInput config={{
onChange:(e)=>{
console.log(e);
}
}} />
/** Example 2 :- */
<PhoneInput onChange={(e)=>{
console.log(e);
}} />
/** Default will find all the keys in output. */
/** Example 1 :- */
<PhoneInput config={{
outputSchema:{
name:false,
number:true,
code:false,
dialCode:true,
flag:false,
phoneNumber:true,
formattedPhoneNumber:true
}
}} />
/** Example 2 :- */
<PhoneInput outputSchema={{
name:false,
number:true,
code:false,
dialCode:true,
flag:false,
phoneNumber:true,
formattedPhoneNumber:true
}} />
/** Default value is IN. */
/** Setting the default country. */
/** Example 1 :- */
<PhoneInput config={{
defaultCountry:"AU"
}} />
/** Example 2 :- */
<PhoneInput defaultCountry="AU" />
/** Default value is +——. */
/** Setting the default country. */
/** Example 1 :- */
<PhoneInput config={{
dialCodePlaceholder:"Country?"
}} />
/** Example 2 :- */
<PhoneInput dialCodePlaceholder="Select country" />
/** Setting the main input placeholder. */
/** Example 1 :- */
<PhoneInput config={{
numberPlaceholder:"Enter phone number"
}} />
/** Example 2 :- */
<PhoneInput numberPlaceholder="Enter phone number" />
/** Disable or changing the dropdown arrow icon */
/** Example 1 :- */
<PhoneInput config={{
dropdownArrow:false
}} />
/** Example 2 :- */
<PhoneInput dropdownArrow={`<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chevron-down" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708"/>
</svg>`} />
/** Default value is true */
/** Enable/Disable the divider line */
/** Example 1 :- */
<PhoneInput config={{
divider:false
}} />
/** Example 2 :- */
<PhoneInput divider={false} />
/** Default value is false */
/** Example 1 :- */
<PhoneInput config={{
focusOnMainInputAfterClose:true
}} />
/** Example 2 :- */
<PhoneInput focusOnMainInputAfterClose={true} />
/** Adding parent class to the root element */
/** Example 1 :- */
<PhoneInput config={{
parentClass:"my-class-1 my-class-2"
}} />
/** Example 2 :- */
<PhoneInput parentClass={"my-class-1 my-class-2"} />
/** Adding class to the label element */
/** Example 1 :- */
<PhoneInput config={{
labelClass:"my-class-1 my-class-2"
}} />
/** Example 2 :- */
<PhoneInput labelClass={"my-class-1 my-class-2"} />
/** Adding class to the main input element */
/** Example 1 :- */
<PhoneInput config={{
mainInputClass:"my-class-1 my-class-2"
}} />
/** Example 2 :- */
<PhoneInput mainInputClass={"my-class-1 my-class-2"} />
/** Adding class to the options container element */
/** Example 1 :- */
<PhoneInput config={{
optionsContainerClass:"my-class-1 my-class-2"
}} />
/** Example 2 :- */
<PhoneInput optionsContainerClass={"my-class-1 my-class-2"} />
/** Adding class to the dial code container element */
/** Example 1 :- */
<PhoneInput config={{
dialCodeContainerClass:"my-class-1 my-class-2"
}} />
/** Example 2 :- */
<PhoneInput dialCodeContainerClass={"my-class-1 my-class-2"} />
/** A listener function on main input focus */
/** Example 1 :- */
<PhoneInput config={{
onMainInputFocus:(e:HTMLInputElement, data:any)=>{
console.log(e, data);
}
}} />
/** Example 2 :- */
<PhoneInput onMainInputFocus={(e:HTMLInputElement, data:any)=>{
console.log(e, data);
}} />
/** A listener function on main input blur */
/** Example 1 :- */
<PhoneInput config={{
onMainInputBlur:(e:HTMLInputElement, data:any)=>{
console.log(e, data);
}
}} />
/** Example 2 :- */
<PhoneInput onMainInputBlur={(e:HTMLInputElement, data:any)=>{
console.log(e, data);
}} />
/** A listener function on open options dropdown */
/** Example 1 :- */
<PhoneInput config={{
onOpenMenu:(data:any)=>{
console.log(data);
}
}} />
/** Example 2 :- */
<PhoneInput onOpenMenu={(data:any)=>{
console.log(data);
}} />
/** A listener function on close options dropdown */
/** Example 1 :- */
<PhoneInput config={{
onCloseMenu:(data:any)=>{
console.log(data);
}
}} />
/** Example 2 :- */
<PhoneInput onCloseMenu={(data:any)=>{
console.log(data);
}} />
/** Default value is true. */
/** Enable/Disable the label. */
/** Example 1 :- */
<PhoneInput config={{
label:false
}} />
/** Example 2 :- */
<PhoneInput label={false} />
/** Changing the label. */
/** Example 1 :- */
<PhoneInput config={{
labelText:"My new label"
}} />
/** Example 2 :- */
<PhoneInput labelText={"My new label"} />
/** We have 2 options here to change the label's view `default`, `fixed_floating`. */
/** Example 1 :- */
<PhoneInput config={{
labelType:"fixed_floating"
}} />
/** Example 2 :- */
<PhoneInput labelType={"fixed_floating"} />
/** Default value is false */
/** Enable/Disable masking */
/** Example 1 :- */
<PhoneInput config={{
masking:true
}} />
/** Example 2 :- */
<PhoneInput masking={true} />
/** Default value is (##) ####-#### */
/** Note :- “#” represents a phone number digit. */
/** Example 1 :- */
<PhoneInput config={{
maskingFormat:"(##) [####]-####"
}} />
/** Example 2 :- */
<PhoneInput maskingFormat={"(##) #### ####"} />
/** Default value is false */
/** This restricts typing based on the masking format. */
/** Example 1 :- */
<PhoneInput config={{
validateMasking:true
maskingFormat:"(##) [####]-####"
}} />
/** Example 2 :- */
<PhoneInput validateMasking={true} maskingFormat={"(##) #### ####"} />
/** Default value is hi for Hindi */
/** Example 1 :- */
<PhoneInput config={{
locale:"en"
}} />
/** Example 2 :- */
<PhoneInput locale={"de"} />
/** Default value is en for English */
/** The library will use this language in case of missing translations */
/** Example 1 :- */
<PhoneInput config={{
fallbackLanguage:"en"
}} />
/** Example 2 :- */
<PhoneInput fallbackLanguage={"de"} />
/** Add a new language translation or overwrite existing translations for any language */
/** Example 1 :- */
<PhoneInput config={{
addOrReplaceLocale:[
{
languageCode:"hi",
data:{
label:"फ़ोन नंबर",
search:"देश खोजें",
countries:{
IN:"भारत",
US:"अमेरिका"
// ... More translations for other country names
}
}
}
]
}} />
/** Example 2 :- */
<PhoneInput addOrReplaceLocale={[
{
languageCode:"hi",
data:{
label:"फ़ोन नंबर",
search:"देश खोजें",
countries:{
IN:"भारत",
US:"अमेरिका"
// ... More translations for other country names
}
}
}
]} />
/** Manages the value of the input. Accepts two types of values. */
/** Example 1 :- */
<PhoneInput config={{
value:"+91 987#######"
}} />
/** Example 2 :- */
<PhoneInput value={{
number:"987#######",
dialCode:"+91"
}} />
/** An id attribute for the main input. It will also be automatically linked to the input label. */
/** Example :- */
<PhoneInput id="myInputID" />
/** The name attribute for the main input.*/
/** Example :- */
<PhoneInput name="myFieldName" />
Ramveer Jat
Maintained with ❤️ by the creator.
FAQs
A lightweight, customizable, multi-language phone input component for React.
We found that react-universal-phone demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.