Search code examples
angulartypescriptmasking

How to do masking using angular 5


Is it possible to create a mask in Angular 5 that looks like this:

XXX-XX-1234

And when the user clicks on the text box it should change to the following text:

1234121234

Thanks a ton!


Solution

  • Yes a mask would do the trick. You could also use a pipe, so that you don't actually change the value, just mask it. Here's a simple example I put together for you:

    https://stackblitz.com/edit/angular-pvmlij?file=src%2Fapp%2Fapp.componenthtml