JSFiddle - React, Tailwind, and code Playground

by Oleh Aloshkin

HTML

<input type="text" value="1" class="product-quantity">

JavaScript

var lastValue = document.getElementsByClassName('product-quantity')[0].value;

document.getElementsByClassName('product-quantity')[0].addEventListener('input', function(event) {
  if (this.value) {
    var numValue = parseInt(this.value);
    if (numValue.toString() != this.value) {
      this.value = lastValue;
      return false;
    } else {
      this.value = parseInt(this.value)
    }
  } else {
    this.value = lastValue;
    return false;
  }
  lastValue = this.value;
}, false);