1

I am using angular and I want an input that displays the text format 614-123-1234. I don't know exactly how to do it, I found something made in jQuery that could help me but I wasn't allowed to install it on my project

My input:

<input type='number' onKeyPress="if(this.value.length==10) return false;"
 class="input" formControlName="cel" id="cel" name="cel">

I want something like this

enter image description here

DreamBold
  • 2,727
  • 1
  • 9
  • 24
Edgar
  • 109
  • 7

1 Answers1

3

You can install ngx-mask package and then specify your ideal mask like this:

mask="(000) 000-000"

< input type="text" mask="(000) 000-000" />

Install ngx-mask

$ npm i ngx-mask

Quickstart

Import ngx-mask module in your Angular app.

With default mask config options:

import { NgxMaskModule, IConfig } from 'ngx-mask'

export const options: Partial<null|IConfig> | (() => Partial<IConfig>) = null;

@NgModule({
  imports: [
    NgxMaskModule.forRoot(),
  ],
})

More about the usage of the ngx-mask package is addressed here.

DreamBold
  • 2,727
  • 1
  • 9
  • 24