New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-universal-phone

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-universal-phone

A lightweight, customizable, multi-language phone input component for React.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

🚀 react-universal-phone

A lightweight, customizable, multi-language phone input component for React.

📦 Installation

Install react-universal-phone with npm.

  npm install react-universal-phone
  or
  yarn add react-universal-phone

✨ Features

  • 🌍 Supports almost all countries.
  • 🈺 Built-in multi-language support (EN, HI, BN, GU, KN, ML, MR, PA, TA, TE, JA, DE, TH, RU…).
  • 🎌 Auto-formatted phone numbers.
  • 🚀 Lightweight & fast
  • 🎨 Fully customizable styles
  • 🔍 Search country feature
  • 🇮🇳 Flags + dial codes included
  • 🧩 Plug-and-play React component

📦 Usage/Examples

import { PhoneInput } from "react-universal-phone";

function App() {
  return <PhoneInput />;
}

export default App;

🌐 Internationalization / Multilingual support

/** 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
 */

⚙️ Props & configurations

ParameterTypeDescription
optionsFormat 🔗stringManage 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 🔗booleanKeep the options dropdown open by default.
dialCodeSelectionFormat 🔗stringChange the format of selected option at the top.
closeOnOutsideClick 🔗booleanClose the options dropdown when clicking outside.
onChange 🔗FunctionA function that listens for changes.
outputSchema 🔗objectDefine which country details should be included in the output.
defaultCountry 🔗string or booleanTo select a default country.
dialCodePlaceholder 🔗string or booleanSet or disable the dial code placeholder.
numberPlaceholder 🔗string or booleanSet or disable the main number placeholder.
dropdownArrow 🔗string or booleanChange or disable the down arrow icon.
divider 🔗booleanEnable/Disable the divider between the dial code & main input
focusOnMainInputAfterClose 🔗booleanFocus on the main number input just after close the options dropdown.
parentClass 🔗stringAdd parent classes on the root element. Multiple also allowed, space separated.
labelClass 🔗stringAdd classes on the label element. Multiple also allowed, space separated.
mainInputClass 🔗stringAdd classes on the main input element. Multiple also allowed, space separated.
optionsContainerClass 🔗stringAdd classes on the root element of options dropdown. Multiple also allowed, space separated.
dialCodeContainerClass 🔗stringAdd classes on the dial code container element. Multiple also allowed, space separated.
onMainInputFocus 🔗FunctionA function to listen for focus events.
onMainInputBlur 🔗FunctionA function to listen for blur events.
onOpenMenu 🔗FunctionA function triggered when open the options dropdown.
onCloseMenu 🔗FunctionA function triggered when close the options dropdown.
label 🔗booleanShow/Hide label.
labelText 🔗stringSet custom text for the label.
labelType 🔗stringdefault, fixed_floating To change the label view.
masking 🔗booleanEnable/Disable masking for the main number input.
maskingFormat 🔗stringTo change adjust the masking format.
validateMasking 🔗booleanThis will allow typing only till the masking format.
locale 🔗stringChange the language for the input completely.
fallbackLanguage 🔗stringA fallback language if any translation is not available in any particular language.
addOrReplaceLocale 🔗LocaleTypesTo add some new or replace existing language translations.
configobjectTo add a global configuration. Most of the props are allowed here in the config object.
value 🔗string or objectValue to set the input.
id 🔗stringInput ID.
name 🔗stringInput name.

🌐 Usage/Example of all the properties

optionsFormat

/** 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" />

addCountries

/** 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: "🧩"
    }
]} />

removeCountries

/** 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"]} />

defaultOpenOptions

/** Keep the options dropdown open by default. */

/** Example 1 :- */
<PhoneInput config={{
    defaultOpenOptions:true
}} />

/** Example 2 :- */
<PhoneInput defaultOpenOptions={true} />

dialCodeSelectionFormat

/** 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"} />

closeOnOutsideClick

/** Default value is true */

/** Example 1 :- */
<PhoneInput config={{
    closeOnOutsideClick:false
}} />

/** Example 2 :- */
<PhoneInput closeOnOutsideClick={false} />

onChange

/** 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);
}} />

outputSchema

/** 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
}} />

defaultCountry

/** Default value is IN. */
/** Setting the default country. */

/** Example 1 :- */
<PhoneInput config={{
    defaultCountry:"AU"
}} />

/** Example 2 :- */
<PhoneInput defaultCountry="AU" />

dialCodePlaceholder

/** Default value is +——. */
/** Setting the default country. */

/** Example 1 :- */
<PhoneInput config={{
    dialCodePlaceholder:"Country?"
}} />

/** Example 2 :- */
<PhoneInput dialCodePlaceholder="Select country" />

numberPlaceholder

/** Setting the main input placeholder. */

/** Example 1 :- */
<PhoneInput config={{
    numberPlaceholder:"Enter phone number"
}} />

/** Example 2 :- */
<PhoneInput numberPlaceholder="Enter phone number" />

dropdownArrow

/** 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>`} />

divider

/** Default value is true */
/** Enable/Disable the divider line */

/** Example 1 :- */
<PhoneInput config={{
    divider:false
}} />

/** Example 2 :- */
<PhoneInput divider={false} />

focusOnMainInputAfterClose

/** Default value is false */

/** Example 1 :- */
<PhoneInput config={{
    focusOnMainInputAfterClose:true
}} />

/** Example 2 :- */
<PhoneInput focusOnMainInputAfterClose={true} />

parentClass

/** 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"} />

labelClass

/** 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"} />

mainInputClass

/** 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"} />

optionsContainerClass

/** 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"} />

dialCodeContainerClass

/** 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"} />

onMainInputFocus

/** 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);
}} />

onMainInputBlur

/** 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);
}} />

onOpenMenu

/** 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);
}} />

onCloseMenu

/** 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);
}} />

label

/** Default value is true. */
/** Enable/Disable the label. */

/** Example 1 :- */
<PhoneInput config={{
    label:false
}} />

/** Example 2 :- */
<PhoneInput label={false} />

labelText

/** Changing the label. */

/** Example 1 :- */
<PhoneInput config={{
    labelText:"My new label"
}} />

/** Example 2 :- */
<PhoneInput labelText={"My new label"} />

labelType

/** 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"} />

masking

/** Default value is false */
/** Enable/Disable masking */

/** Example 1 :- */
<PhoneInput config={{
    masking:true
}} />

/** Example 2 :- */
<PhoneInput masking={true} />

maskingFormat

/** Default value is (##) ####-#### */
/** Note :- “#” represents a phone number digit. */

/** Example 1 :- */
<PhoneInput config={{
    maskingFormat:"(##) [####]-####"
}} />

/** Example 2 :- */
<PhoneInput maskingFormat={"(##) #### ####"} />

validateMasking

/** 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={"(##) #### ####"} />

locale

/** Default value is hi for Hindi */

/** Example 1 :- */
<PhoneInput config={{
    locale:"en"
}} />

/** Example 2 :- */
<PhoneInput locale={"de"} />

fallbackLanguage

/** 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"} />

addOrReplaceLocale

/** 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
        }
    }
    }
]} />

value

/** 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"
}} />

id

/** An id attribute for the main input. It will also be automatically linked to the input label. */

/** Example :- */
<PhoneInput id="myInputID" />

name

/** The name attribute for the main input.*/

/** Example :- */
<PhoneInput name="myFieldName" />

👨‍💻 Author

Ramveer Jat
Maintained with ❤️ by the creator.

Keywords

react

FAQs

Package last updated on 08 Dec 2025

Did you know?

Socket

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.

Install

Related posts