# angular2-text-mask

> Angular 2 directive for input text masking

Latest version **9.0.0** (published 2018-05-01) · Unlicense license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 9.0.0 |
| Published | 2018-05-01 |
| First published | 2016-05-30 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 27 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8204 |
| Author | M.K. Safi |
| Maintainers | lozjackson, msafi |
| Keywords | angular2, ng2, angular2 component, angular2 directive, text mask, input mask, string mask, input formatting, text formatting, string formatting |

## Links

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

## Dependencies (1)

- [text-mask-core](https://npm.io/package/text-mask-core.md) ^5.0.0

## 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

- 9.0.0 (latest) — 2018-05-01
- 0.18.0-2 (form-control) — 2016-08-20
- 8.0.5 — 2018-04-23
- 8.0.4 — 2017-09-05
- 8.0.3 — 2017-08-01
- 8.0.2 — 2017-06-21
- 8.0.1 — 2017-04-28
- 8.0.0 — 2017-03-31
- 7.0.0 — 2017-03-22
- 6.3.2 — 2017-03-13
- 6.3.1 — 2017-03-09
- 6.3.0 — 2017-03-08
- 6.2.0 — 2017-03-07
- 6.1.0 — 2017-02-27
- 6.0.0 — 2017-02-25
- … 54 more at https://npm.io/package/angular2-text-mask/versions

## README

# Angular 2 Input Mask

## Getting started

First, install it.

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

Then, import it into your `@NgModule`:

```typescript
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { TextMaskModule } from 'angular2-text-mask';

@NgModule({
  imports: [
    FormsModule,
    TextMaskModule
  ],
  declarations: []
})
export class MyModule {}
```

Then, use it in your component:
```typescript
@Component({
  selector: 'app',
  template: `
    <input [textMask]="{mask: mask}" [(ngModel)]="myModel" type="text"/>
  `
})
export class AppComponent {
  public myModel = ''
  public mask = ['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]
}
```

## Documentation

As you can see in the code above, you are passing an object to the `textMask` directive.

&#x1F4CD; For more information about the values that the `textMask` object accepts, see 
**[this page](https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#readme)**.

#### Other use-cases

##### Unmasking the value that is stored in the model

Text Mask does not provide an option to unmask the model before storing it. You can sanitize the model on your
side. See [here](https://github.com/text-mask/text-mask/issues/109) for details.

##### `change` doesn't work

`change` on an input field will not work if `[text-mask]` is present. You can use `(ngModelChange)` instead. For more 
information, see [this page](https://github.com/text-mask/text-mask/issues/236).

## 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. `cd angular2`
1. `npm install`
1. `npm start`
1. Open [http://localhost:3000](http://localhost:3000)

The code of the example is in [`angular2/example`](https://github.com/text-mask/text-mask/tree/master/angular2/example).

## Ionic 2
Unfortunately, we are unable to support Ionic 2 `ion-input` at this point as it overrides the `ControlValueAccessor` that Text Mask requires to perform its job.

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