The person types their height (which always has three digits). I want autocomplete, example: -
The person types- 200
And the software will convert to 2.00
The person types their height (which always has three digits). I want autocomplete, example: -
The person types- 200
And the software will convert to 2.00
If you always have 3 digits, then limit the input
with the maxlength
attribute that specifies the maximum number of characters that the user can enter.
<input class="number" maxlength="3">
Javascript
It does not allow typing different values of numbers and after entering the third number, inserts the comma automatically after the first number entered.
var el = document.querySelector('input.number');
el.addEventListener('keyup', function (event) {
if (event.which >= 37 && event.which <= 40) return;
this.value = this.value.replace(/\D/g, '').replace(/\B(?=(\d{2})+(?!\d))/g, ',');
});
<input class="number" maxlength=3>