Doubt - insert html mask

1

Hello,

I need to put a mask as follows:

I have a field:

<input type="text" required maxlength="4" name="minimumGrade" id="minimumGrade" ng-model="capacity.minimumGrade">

It is necessary that in this field it receives only three digits (numbers) and that when typing it has a mask like this:

#.##

It should be in the form of "note", example: 9.00, 7.50 and so on ...

    
asked by anonymous 16.11.2016 / 13:18

2 answers

0
<input type="number" pattern="(\d{3})([\.])(\d{2})">

It should solve your problem, but it is not quite a masquerade it will be necessary to put the points and commas.

Only mask js

jQuery-Mask

    
16.11.2016 / 13:23
0

As @MarcoViniciusSoaresDalalba quoted, with attribute pattern the user should still put . or , .

To really put a mask on, use the JQuery Mask Plugin library of Igor Escobar. With it, you can use annotations to make your code easier and that works very well.

Your code looks like this:

<input type="text" required maxlength="4" name="minimumGrade"  id="minimumGrade" ng-model="capacity.minimumGrade" data-mask="9.99">

And the result of this input will be as expected: 7.89, 9.45, 2.47.

    
16.11.2016 / 14:31