How to add limit value along with jquery mask?

0

I'm using the mask plugin for this link: link

I use the following jquery to do the mask:

$('.decimal').mask('000,0', {reverse: true});

However I need the maximum value to be 100.0. I've tried putting

$('.decimal').mask('100,0', {reverse: true});

But it does not work because 0 means any number so the person can put up to 199.9.

Can anyone help me?

    
asked by anonymous 04.06.2018 / 02:19

1 answer

0

You can onKeyPress event, replace the comma by the point and check if it is greater than 100.0:

$('.decimal').mask('000,0', {
  reverse: true,
  onKeyPress: function(val, e, field, options) {
    if (val.replace(',', '.') > 100.0) {
      $('.decimal').val('')
    }
  }
});

See working:

$('.decimal').mask('000,0', {
  reverse: true,
  onKeyPress: function(val, e, field, options) {
    if (val.replace(',', '.') > 100.0) {
      console.clear();
      console.log('Valor maximo 100,0 !');
      $('.decimal').val('');
    }
  }
});
<script src="https://code.jquery.com/jquery-2.2.4.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.15/jquery.mask.js"></script>
<input type="text" class="decimal">

Reference:

04.06.2018 / 03:01