Have "APP" as prefix and then allow only numbers in input field

Issue

I have a requirement where I have an input field, that must have the prefix "APP " and then allow the user to type in 7 numeric only values. I was hoping I could use ngx-mask, but it doesn’t seem possible. Alternatively I was thinking of using (focusin) event like:

(focusin)="addPrefix($event)"

inputValue = "";
addPrefix(ev: any){
 inputValue = "APP ";
}

and then having a keyup event which would disregard key presses if input.length <= 3.But then comes this issue of pasting values in. Does anyone else have any better ideas/suggestions? Thanks

Solution

Stackblitz

How about,

<input type="text" prefix="APP " mask="0000000" [clearIfNotMatch]="true" />

using ngx-mask?

Answered By – Andrew Allen

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.