Socket
Socket
Sign inDemoInstall

angular2-text-mask

Package Overview
Dependencies
0
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    angular2-text-mask

Angular 2 directive for input text masking


Version published
Maintainers
1
Install size
349 kB
Created

Readme

Source

Angular 2 Input Mask

This Angular 2 Directive is also compatible with Ionic 2 ion-input.

Getting started

First, install it.

npm i angular2-text-mask --save

Then, import it into your @NgModule and declare it:

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

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

Then, use it in your component:

@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.

📍 For more information about the values that the textMask object accepts, see this page.

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 for details.

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 angular2:dev
  5. Open http://localhost:3000

The code of the example is in angular2/example.

Contributing

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

Keywords

FAQs

Last updated on 29 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc