0

$(document).on("input", ".money", function(e) {
  console.log(moneyonly($(this).val()))
  if (moneyonly($(this).val())) {
    return true;

  }
  return false;
});


function moneyonly(amount) {
  var boo = false;

  if ((/^\d*(?:\.\d{2})?$/g).test(amount)) {
    boo = true;
  }
  return boo;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="money" id="">

Regex is ok. Even if false it is still typing in the input. How to not allow?

How to allow only the format that is assigned in regex? Any idea is appreciated

Pekka
  • 1,075
  • 2
  • 10
  • 17

1 Answers1

0

That is widely supported across browsers

<input type="number" min="1" max="5" step=0.001 />
kidwon
  • 4,448
  • 5
  • 28
  • 45