Home > Enterprise >  how to make a mac address mask in angular 13
how to make a mac address mask in angular 13

Time:03-30

I have an input field in which the user have to type a MAC Address, but i wanted to apply a mask that:

  1. if the person entered with the 12 digits without the ':' it would automatically complete it
  2. if its not valid, then i could disable the form and send an error message

Can someone help me with this?

I tried using

mask="FF:FF.FF:FF.FF:FF"

in the input field, using the https://www.npmjs.com/package/ngx-mask documentation but it didnt work

CodePudding user response:

you need to use "A" instead of "F" for this. It'd be something like

<input type="text" mask="AA:AA.AA:AA.AA:AA" />

CodePudding user response:

I discovered what was worng hehe Turns out i've imported the ngxMaskModule in the appModule but not in the module of the component of my form, so it wasnt throwing any errors, but it wasnt working either.

Well, make sure to add it to your component's module if you need to use it. Use the forRoot() in the appModule and forChild() in the component's, just like this:

NgxMaskModule.forChild()

  • Related