包详细信息

react-number-formatter

faraazHasan118MIT1.0.29

This react input component automatically formats phone numbers inside input and returns the number you actually typed.

react, phone, number, format

自述文件

react-number-formatter

This React input component automatically formats phone numbers as you type and returns the actual number you entered. 😊

Installation

Run this command in your terminal

npm add react-number-formatter
Props Description
getCountryCode To get selected country code
format To create your own format
defaultCountry To make a country default selected
onlyCountries To filter country options
fixLength To limit input length
disabled To make input and selector disable
fullIsoCode Sets 3 letter ISO Code e.g. "IND", "USA"
searchOption To add or remove search bar
register To use this input inside react-hook-form
flags: Boolean To get country code instead of flag
placeholder: String To change placeholder
initialFormat: Boolean When using this component in editable forms. this function automatically guess the the dial code and formats the number

Demo with hook form

Normal Usage

import { NumberFormatter } from 'react-number-formatter';
const [number, setNumber] = useState();
//for typescript
const [number, setNumber] = useState<string | number>();

Screenshot 2023-05-14 at 1 55 15 PM

#

<NumberFormatter
  value={number}
  initialFormat={true}
  getValue={(n: string) => setNumber(n)}
/>

Screen Recording 2023-05-14 at 2 03 26 PM

You can create your own format.

<NumberFormatter
  format={"+1 (###)-(###)-####"}
  value={number}
  getValue={(n: string) => setNumber(n)}
/>

Screen_Recording_2023-02-19_at_8_03_19_PM_AdobeExpress