NgMask force custom pattern

I have an AngularJS project where I am using NgMask plugin, I want to force users to enter a specific pattern inside an input box.

Pattern example goes like: X01Y1234Z55

Where X,Y and Z are static characters, and users shouldn't be able to enter any other characters other than them, and the digits count should remain the same, X .. 2 Digits .. Y .. 4 Digits .. Z .. 2 Digits.

I have tried to use:

<input type="text" ng-model="unique_id" mask="X99Y9999Z99" restrict="reject">

but unfortunately that didn't work.

I am not familiar with Regex complicated stuff, so I am hoping that some Regex experts can help us out with that.

Thanks.

#angular.js #regex

4 Likes19.75 GEEK