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

react-phone-input-pro

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-phone-input-pro

Phone number input component for react to format phone numbers according to selected countries in real time.

latest
Source
npmnpm
Version
1.0.11
Version published
Maintainers
0
Created
Source

react-phone-input-pro

Phone number input component for react to format phone numbers according to selected country in real time.

Features

  • Easy to use - just import and use.
  • Lightweight - No third-party dependencies.
  • Search bar - You can anable or disable search bar from countries options list.
  • You have option to include or exclude dial code from number.
  • You can create your own formats

Installation

Run this command in your terminal

npm install react-phone-input-pro
PropsDescription
initialFormat: BooleanWhen using this component in editable forms. this function automatically guess the the dial code and formats the number
prefix: Booleanuser will get dial code pre defined When this is true or undefined
className: StringTo add a css class in this component
includeDialingCode: BooleanIf you don't want to include dial code in number then make this false
placeholder: StringTo change placeholder
onchange: Function()This function returns current unformatted value. Which you can use to setState of value.
onlyCountries: ArrayTo filter country options. e.g.: ["USA", "IND"]
fixLength: BooleanTo limit input length
disabled: BooleanTo make input and selector disable
fullIsoCode: BooleanSets 3 letter ISO Code e.g. "IND", "USA"
searchOption: BooleanTo add or remove search bar
getCountryCode: Function()To get selected country code
flags: BooleanTo get country code instead of flag
error: [errorStatus:boolean, errorMessage:string]To show error message
Screenshot 2023-05-14 at 1 37 55 PM

Usage

import PhoneInput from 'react-phone-input-pro';
const [number, setNumber] = useState();
const [err, setErr] = useState(false);
//for typescript
const [number, setNumber] = useState<string | number>();
 const [err, setErr] = useState(false);

Example: Inside React-hook-form

<Controller
  control={control}
  name={"phone"}
  render={({ field: { onChange, value } }) => (
    <PhoneInput
      value={value}
      prefix
      onchange={(n: string) => {
        onChange(n);
      }}
    />
  )}
/>

Normal use

<PhoneInput
  initialFormat={true} 
  value={number}
  prefix={true}
  onchange={(n) => setNumber(n)}
  fullIsoCode={true}
/> 

Untitled

Create your own format

<PhoneInput 
   value={number}
   initialFormat={true} 
   prefix={true}
   placeholder={"Phone number..."}
   fixLength={true}
   format={"+100 #,##-(###)/##,##"}
   fullIsoCode={true}
   searchOption={true}
   onchange={(n)=> setPhone(n)} 
 />

Screen Recording 2023-05-27 at 9 14 55 PM

Error handling

<PhoneInput
  value={number}
  initialFormat={true}
  prefix={false}
  placeholder={"Phone number..."}
  error={[err, "Invalid Number"]}
  fullIsoCode={true} 
  searchOption={true}
  onchange={(value: string)=> {
    setNumber(value)
    setErr(false);
  }}
/> 

Screen Recording 2023-05-06 at 8 35 22 PM

Based on react-number-formatter

Keywords

react

FAQs

Package last updated on 06 Jul 2024

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