Doubt - insert html mask

Asked

Viewed 635 times

1

Hello,

I need to put a mask on as follows:

I have a field:

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

And I need that in this field it receives only three digits (numbers) and that when typing it gets a mask like this:

#.##

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

2 answers

0


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

should solve your problem, but it is not well a mask will be necessary to put the stitches and commas.

mask only with js

jQuery-Mask

  • It didn’t work out like Pattern, it passes the Qtd of characters I wish...

  • http://html5pattern.com/Dates for more about Pattern Example using jquery-Mask (needs jquery) https://jsfiddle.net/1zt9abp2/

  • It worked out! Thank you!

0

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

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

Your code will look like this:

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

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

  • Hello, I did as you passed above imported the libraries, but it does not work... You can send me an example?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.