react-number-format vs react-input-mask vs react-text-mask vs react-currency-input-field vs react-numeric-input
Input Masking and Formatting Libraries for React Comparison
1 Year
react-number-formatreact-input-maskreact-text-maskreact-currency-input-fieldreact-numeric-inputSimilar Packages:
What's Input Masking and Formatting Libraries for React?

Input masking and formatting libraries for React are tools that help developers create input fields with specific formatting rules. These libraries enhance user experience by guiding users to enter data in a predefined format, such as phone numbers, credit card numbers, dates, or currency values. They can automatically add masks, separators, or formatting as the user types, ensuring that the input is valid and consistent. This is particularly useful for applications that require structured data entry, such as forms, e-commerce sites, and financial applications. By using these libraries, developers can reduce errors, improve data quality, and create a more intuitive interface for users.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-number-format1,663,6353,954240 kB2292 months agoMIT
react-input-mask615,5742,255-1396 years agoMIT
react-text-mask373,7368,26048.8 kB334-Unlicense
react-currency-input-field231,666708310 kB33 days agoMIT
react-numeric-input34,240279-637 years agoMIT
Feature Comparison: react-number-format vs react-input-mask vs react-text-mask vs react-currency-input-field vs react-numeric-input

Input Masking

  • react-number-format:

    react-number-format supports input masking for numbers, currencies, and percentages, allowing for customizable formatting and masking as the user types.

  • react-input-mask:

    react-input-mask provides robust input masking capabilities, allowing developers to define custom masks for various input types, including phone numbers, dates, and more.

  • react-text-mask:

    react-text-mask allows for the creation of custom input masks, providing flexibility in defining how the input should be formatted as the user types.

  • react-currency-input-field:

    react-currency-input-field does not provide traditional input masking but formats the input as currency while the user types, ensuring the value is always displayed in a currency format.

  • react-numeric-input:

    react-numeric-input does not provide input masking but restricts input to numeric values, making it easy to enter numbers without additional formatting.

Currency Formatting

  • react-number-format:

    react-number-format offers comprehensive currency formatting features, including support for multiple currencies, customizable symbols, and the ability to format values as the user types.

  • react-input-mask:

    react-input-mask does not handle currency formatting but can be used in conjunction with other libraries to create masked inputs for currency fields.

  • react-text-mask:

    react-text-mask does not provide currency formatting but can be used to create masked input fields for currency values with the help of additional formatting logic.

  • react-currency-input-field:

    react-currency-input-field specializes in currency formatting, automatically adding currency symbols, commas, and decimal points based on the specified currency type.

  • react-numeric-input:

    react-numeric-input does not provide built-in currency formatting but can be combined with other libraries to format numeric values as currency.

Customization

  • react-number-format:

    react-number-format offers extensive customization options for formatting numbers, currencies, and percentages, including the ability to set decimal places, thousand separators, and more.

  • react-input-mask:

    react-input-mask is highly customizable, allowing developers to create complex mask patterns and define how the input should behave.

  • react-text-mask:

    react-text-mask allows for customization of the mask patterns and the behavior of the input, making it flexible for various use cases.

  • react-currency-input-field:

    react-currency-input-field allows for some customization, such as changing the currency symbol and formatting rules, but is primarily focused on currency inputs.

  • react-numeric-input:

    react-numeric-input provides limited customization, primarily around the appearance of the numeric input and the range of values allowed.

Ease of Use: Code Examples

  • react-number-format:

    Formatted number input example with react-number-format

    import React from 'react';
    import NumberFormat from 'react-number-format';
    
    const NumberFormatExample = () => {
      return (
        <NumberFormat
          thousandSeparator
          decimalScale={2}
          fixedDecimalScale
          prefix="$"
          placeholder="Enter amount"
        />
      );
    };
    
    export default NumberFormatExample;
    
  • react-input-mask:

    Phone number input example with react-input-mask

    import React from 'react';
    import InputMask from 'react-input-mask';
    
    const PhoneNumberInput = () => {
      return (
        <InputMask mask="(999) 999-9999" placeholder="(123) 456-7890">
          {(inputProps) => <input {...inputProps} />}
        </InputMask>
      );
    };
    
    export default PhoneNumberInput;
    
  • react-text-mask:

    Text input with custom mask using react-text-mask

    import React from 'react';
    import { MaskedInput } from 'react-text-mask';
    
    const TextMaskExample = () => {
      return (
        <MaskedInput
          mask={[/[A-Z]/, /[A-Z]/, /[A-Z]/, ' ', /[0-9]/, /[0-9]/, /[0-9]/]}
          placeholder="ABC 123"
        />
      );
    };
    
    export default TextMaskExample;
    
  • react-currency-input-field:

    Simple currency input example with react-currency-input-field

    import React from 'react';
    import CurrencyInput from 'react-currency-input-field';
    
    const CurrencyInputExample = () => {
      return (
        <CurrencyInput
          id="currency-input"
          name="currency"
          placeholder="Enter amount"
          defaultValue=""
          decimalsLimit={2}
          prefix="$"
        />
      );
    };
    
    export default CurrencyInputExample;
    
  • react-numeric-input:

    Simple numeric input example with react-numeric-input

    import React from 'react';
    import NumericInput from 'react-numeric-input';
    
    const NumericInputExample = () => {
      return <NumericInput min={0} max={100} step={1} />;
    };
    
    export default NumericInputExample;
    
How to Choose: react-number-format vs react-input-mask vs react-text-mask vs react-currency-input-field vs react-numeric-input
  • react-number-format:

    Opt for react-number-format if you need a comprehensive library that supports number, currency, and percentage formatting with advanced features like thousand separators, decimal precision, and input validation.

  • react-input-mask:

    Select react-input-mask if you require a flexible and highly customizable input masking solution that supports various mask patterns, including phone numbers, dates, and custom formats.

  • react-text-mask:

    Use react-text-mask if you need a simple and effective way to create masked input fields with support for custom masks, making it suitable for applications that require specific input formats.

  • react-currency-input-field:

    Choose react-currency-input-field if you need a simple and lightweight solution for formatting currency inputs with support for multiple currencies and customizable formatting.

  • react-numeric-input:

    Pick react-numeric-input if you want a straightforward numeric input component that allows users to enter numbers using a spinner interface, making it ideal for scenarios where precise numeric input is required.

README for react-number-format

Actions Status

react-number-format

React Number Format is an input-formatter library with a sophisticated and light weight caret engine. It ensures that a user can only enter text that meets specific numeric or string patterns, and formats the input value for display.

Features

  1. Prefix, suffix and thousands separator.
  2. Input Masking.
  3. Format number in an input or format as a simple text.
  4. Custom pattern formatting.
  5. Custom formatting handler.
  6. Fully customizable

Demos

See the many DEMO sections in the documentation.

Install

npm

Using npm

npm install react-number-format

Using yarn

yarn add react-number-format

Documentation

Read the full documentation here https://s-yadav.github.io/react-number-format/docs/intro

ES6

Numeric Format

import { NumericFormat } from 'react-number-format';

NumericFormat Props: https://s-yadav.github.io/react-number-format/docs/numeric_format

Pattern Format

import { PatternFormat } from 'react-number-format';

PatternFormat Props: https://s-yadav.github.io/react-number-format/docs/pattern_format

Migrate from v4 to v5

https://s-yadav.github.io/react-number-format/docs/migration

v4 doc

v4 Docs

Development

  • Clone the repository or download the zip
  • npm i -g yarn to download Yarn
  • yarn to install dependencies
  • yarn start to run example server (http://localhost:8084/)
  • yarn test to test changes
  • yarn build to bundle files

Testing

Test cases are written in jasmine and run by karma

Test files : /test/**/*.spec.js

To run test : yarn test