0

i have to allow only number like these:

  • 2 or 45 (from 0 to 99)
  • 2.50 or 35.75 (2 digits before dot and 2 digits after)

Someone can help me? I could limit only int in this way:

$('#valueSconto').on('input', function () {
    this.value = this.value.replace(/[^0-9]/g, '');
});

1 Answers1

0

Try setting input maxlength to 5 ; utilizing .val(function(index, val)) ; RegExp /\d{3}|[^\d{2}\.]|^\./

$("#valueSconto").on("input", function() {
  $(this).val(function(i, val) {
    return val.replace(/\d{3}|[^\d{2}\.]|^\./g, "");
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<input type="text" id="valueSconto" maxlength="5" />
guest271314
  • 1
  • 15
  • 104
  • 177