Answers for "limit html input to two decimal places"

2

limit html input to two decimal places

//Force User Input to Two Decimal Places
//From https://stackoverflow.com/questions/46321683/javascript-restrict-input-once-2-decimal-places-have-been-reached

//HTML Code
<input type="text" oninput="validate(this)" />
  
//JavaScript Code
<script type="text/javascript">
var validate = function(e) {
  var t = e.value;
  e.value = (t.indexOf(".") >= 0) ? (t.substr(0, t.indexOf(".")) + t.substr(t.indexOf("."), 3)) : t;
}
</script>
Posted by: Guest on May-06-2022

Code answers related to "limit html input to two decimal places"

Code answers related to "Javascript"

Browse Popular Code Answers by Language