react-text-mask vs inputmask vs cleave.js vs text-mask-addons vs @maskito/core vs vanilla-text-mask
Input Masking Libraries Comparison
1 Year
react-text-maskinputmaskcleave.jstext-mask-addons@maskito/corevanilla-text-maskSimilar Packages:
What's Input Masking Libraries?

Input masking libraries provide a way to format user input in real-time as they type, ensuring that the data entered matches a specific format. This is particularly useful for fields like phone numbers, credit card numbers, dates, and other structured data. These libraries enhance user experience by guiding users on the expected input format, reducing errors, and improving data consistency.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-text-mask358,4598,24848.8 kB334-Unlicense
inputmask279,8796,4451.4 MB661a year agoMIT
cleave.js255,12017,931-2195 years agoApache-2.0
text-mask-addons216,7168,248-3347 years agoUnlicense
@maskito/core148,9561,540105 kB2514 days agoApache-2.0
vanilla-text-mask20,1658,248-3347 years agoUnlicense
Feature Comparison: react-text-mask vs inputmask vs cleave.js vs text-mask-addons vs @maskito/core vs vanilla-text-mask

Customization

  • react-text-mask:

    React-text-mask allows for customization through props, enabling developers to create tailored input experiences that fit their application's needs while maintaining React's declarative nature.

  • inputmask:

    Inputmask allows for detailed customization of masks, including placeholder characters and validation rules, making it a powerful choice for complex input requirements.

  • cleave.js:

    Cleave.js provides basic customization through predefined formats, but it may not offer as much flexibility as other libraries for complex scenarios. It's best for standard input formats.

  • text-mask-addons:

    Text-mask-addons offers additional customization options on top of text-mask, allowing for more complex masking scenarios and behaviors, enhancing the overall flexibility of input handling.

  • @maskito/core:

    @maskito/core offers extensive customization options, allowing developers to define their own mask patterns and behaviors. This flexibility makes it suitable for a wide range of input types and formats.

  • vanilla-text-mask:

    Vanilla-text-mask provides a straightforward way to customize masks, but it may require more manual configuration compared to other libraries.

Framework Compatibility

  • react-text-mask:

    React-text-mask is specifically built for React applications, ensuring optimal performance and integration with React's lifecycle methods and state management.

  • inputmask:

    Inputmask is also framework-agnostic, but it has specific integrations available for jQuery, React, and Angular, providing flexibility depending on your tech stack.

  • cleave.js:

    Cleave.js is framework-agnostic and can be easily integrated into any project, whether it's vanilla JavaScript or a specific framework.

  • text-mask-addons:

    Text-mask-addons is designed to work with text-mask, which is also framework-agnostic, but it is primarily used in conjunction with React or Angular projects.

  • @maskito/core:

    @maskito/core is designed to work seamlessly with various frameworks, including React, Vue, and Angular, making it a versatile choice for multi-framework projects.

  • vanilla-text-mask:

    Vanilla-text-mask is a pure JavaScript solution, making it easy to use in any environment without dependencies on frameworks.

Learning Curve

  • react-text-mask:

    React-text-mask is relatively easy to learn for those familiar with React, as it follows React's component-based principles and is well-documented.

  • inputmask:

    Inputmask may have a steeper learning curve due to its extensive options and configurations, but its documentation provides clear guidance for implementation.

  • cleave.js:

    Cleave.js has a low learning curve, with simple setup and usage, making it ideal for developers who need quick input formatting without extensive configuration.

  • text-mask-addons:

    Text-mask-addons has a moderate learning curve, especially for those already familiar with text-mask, as it builds upon existing knowledge.

  • @maskito/core:

    @maskito/core has a moderate learning curve due to its flexibility and customization options, but it is well-documented, making it easier for developers to get started.

  • vanilla-text-mask:

    Vanilla-text-mask has a low learning curve, making it accessible for developers who prefer a straightforward, no-frills approach to input masking.

Performance

  • react-text-mask:

    React-text-mask is designed to be performant within React applications, leveraging React's rendering optimizations to ensure smooth user experiences.

  • inputmask:

    Inputmask is efficient but may experience performance issues with very complex masks or large datasets. Proper configuration can mitigate these issues.

  • cleave.js:

    Cleave.js is lightweight and performs well, making it suitable for applications where performance is critical and minimal overhead is desired.

  • text-mask-addons:

    Text-mask-addons maintains good performance, but its impact depends on the complexity of the masks being used in conjunction with text-mask.

  • @maskito/core:

    @maskito/core is optimized for performance, ensuring minimal impact on input speed and responsiveness, even with complex masks.

  • vanilla-text-mask:

    Vanilla-text-mask is lightweight and performs well, making it a good choice for applications that require fast input handling.

Community and Support

  • react-text-mask:

    React-text-mask benefits from the large React community, with plenty of resources, tutorials, and support available for developers.

  • inputmask:

    Inputmask has a long-standing community and extensive documentation, making it easy to find solutions and support for various use cases.

  • cleave.js:

    Cleave.js has a solid community and good documentation, providing ample resources for developers seeking help or examples.

  • text-mask-addons:

    Text-mask-addons has a smaller community but is supported by the text-mask community, providing access to shared knowledge and resources.

  • @maskito/core:

    @maskito/core has a growing community and active support, with regular updates and improvements based on user feedback.

  • vanilla-text-mask:

    Vanilla-text-mask has a modest community, but its simplicity means that most developers can quickly adapt it without extensive support.

How to Choose: react-text-mask vs inputmask vs cleave.js vs text-mask-addons vs @maskito/core vs vanilla-text-mask
  • react-text-mask:

    Use react-text-mask if you are building a React application and want a seamless integration of input masking. It allows for easy customization and is designed to work well with React's component-based architecture.

  • inputmask:

    Opt for inputmask if you need a robust solution with extensive options for input formatting and validation. It supports a wide range of input types and is particularly useful for complex masking scenarios.

  • cleave.js:

    Select cleave.js if you require a lightweight library that provides a simple way to format input fields, especially for phone numbers, credit cards, and dates. Its straightforward setup and minimal configuration make it ideal for quick implementations.

  • text-mask-addons:

    Choose text-mask-addons if you are already using text-mask and need additional features like custom masks or enhanced functionality. It extends the capabilities of text-mask for more complex use cases.

  • @maskito/core:

    Choose @maskito/core if you need a modern, flexible, and customizable input masking solution that supports various frameworks and vanilla JavaScript. It offers a clean API and is designed for high performance with minimal overhead.

  • vanilla-text-mask:

    Select vanilla-text-mask if you prefer a simple, framework-agnostic solution for input masking. It provides a straightforward approach to input masking without the overhead of additional dependencies.

README for react-text-mask

React Input Mask

Getting started

First, install it.

npm i react-text-mask --save

Then, require it and use it.

import React from 'react'
import MaskedInput from 'react-text-mask'

export default () => (
  <div>
    <MaskedInput
      mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
    />
  </div>
)

<MaskedInput/> is fully compatible with <input/> element. So, you can pass it CSS classes, a placeholder attribute, or even an onBlur handler.

For example, the following works:

<MaskedInput
  mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
  className="form-control"
  placeholder="Enter a phone number"
  guide={false}
  id="my-input-id"
  onBlur={() => {}}
  onChange={() => {}}
/>

Documentation

For more information about the props that you can pass to the component, see the documentation here.

Example

To see an example of the code running, follow these steps:

  1. Clone the repo, git clone git@github.com:text-mask/text-mask.git
  2. cd text-mask
  3. npm install
  4. npm run react:dev
  5. Open http://localhost:3000

The code of the example is in react/example.

Customize Rendered <input> Component

For advanced uses, you can customize the rendering of the resultant <input> via a render prop. This is entirely optional, if no render prop is passed, a normal <input> is rendered.

For example, to use with styled-components, which requires an innerRef:

<MaskedInput
  mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
  placeholder="Enter a phone number"
  id="my-input-id"
  render={(ref, props) => (
    <MyStyledInput innerRef={ref} {...props} />
  )}
/>

const MyStyledInput = styled.input`
  background: papayawhip;
`;

Contributing

We would love some contributions! Check out this document to get started.