# react-text-mask

> React input component that accepts mask pattern

Latest version **5.5.0** (published 2022-10-01) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install react-text-mask
pnpm add react-text-mask
yarn add react-text-mask
bun add react-text-mask
```

## Health

**Score 18/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.5.0 |
| Published | 2022-10-01 |
| First published | 2016-05-30 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | separate (@types/react-text-mask) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 47.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8205 |
| Author | M.K. Safi |
| Maintainers | msafi, browniefed, lozjackson |
| Keywords | react, react-component, text mask, input mask, string mask, input formatting, text formatting, string formatting |

## Links

- npm: https://www.npmjs.com/package/react-text-mask
- Repository: https://github.com/text-mask/text-mask
- Homepage: https://github.com/text-mask/text-mask/tree/master/react/#readme
- Issues: https://github.com/text-mask/text-mask/issues
- npm.io page: https://npm.io/package/react-text-mask

## Dependencies (1)

- [prop-types](https://npm.io/package/prop-types.md) ^15.5.6

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 5.5.0 (latest) — 2022-10-01
- 5.4.3 — 2018-07-25
- 5.4.2 — 2018-06-14
- 5.4.1 — 2018-05-07
- 5.4.0 — 2018-04-29
- 5.3.2 — 2018-04-27
- 5.3.1 — 2018-04-20
- 5.3.0 — 2018-04-05
- 5.2.1 — 2018-03-21
- 5.2.0 — 2018-03-15
- 5.1.0 — 2018-01-07
- 5.0.2 — 2017-05-12
- 5.0.1 — 2017-04-18
- 5.0.0 — 2017-04-15
- 4.1.0 — 2017-03-31
- … 34 more at https://npm.io/package/react-text-mask/versions

## README

# React Input Mask

## Getting started

First, install it.

```bash
npm i react-text-mask --save
```

Then, require it and use it.

```js
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:

```js
<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](https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#readme).

## 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`
1. `cd text-mask`
1. `npm install`
1. `npm run react:dev`
1. Open [http://localhost:3000](http://localhost:3000)

The code of the example is in [`react/example`](https://github.com/text-mask/text-mask/tree/master/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](https://www.styled-components.com/docs/advanced#refs):

```js
<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](https://github.com/text-mask/text-mask/blob/master/howToContribute.md#readme) to get started.

---
_Source: https://npm.io/package/react-text-mask · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
