JSFiddle - React, Tailwind, and code Playground

HTML

<div className="tooltip">
<span id="invalid_entry"></span>
  <input
    className="partial-quantity-input"
    id="quantity-input"
    type="number"
    min="0"
    max="4"
  />
  <!-- <span className="tooltiptext">Exceeds original ordered quantity.</span> -->
</div>

CSS

.partial-quantity-input {
  background: rgb(255, 255, 255);
  border-radius: 0px;
  border: 1px solid rgb(255, 255, 255);
  height: 40px;
  width: 40px;
  outline: none;

  &:focus {
    border: 1px solid rgb(201, 200, 200);
  }
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type='number'] {
  -moz-appearance: textfield;
}

input:invalid {
  outline: none;
  border: 1px solid red;
}

.tooltip {
  position: relative;
  display: inline-block;
}

.tooltip .tooltiptext {
  visibility: hidden;
  bottom: 100%;
  left: 50%;
  margin-left: -60px;
  width: 120px;
  color: rgb(0, 0, 0);
  text-align: center;
  padding: 5px 0;
  background: rgb(255, 255, 255);
  border-radius: 3px;
  border: 1px solid rgb(220, 220, 220);
  height: 38px;
  width: 252px;

  /* Position the tooltip */
  position: absolute;
  z-index: 1;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}

#invalid_entry {
  display: none;
  background: orange;
  padding: 6px;
  color: #fff;
  position: absolute;
  left: 20px;
  top: 28px;
}

JavaScript

let input = document.getElementById("quantity-input");
let tooltip = document.getElementById("invalid_entry");
input.addEventListener("keyup", function(e){
  if(e.currentTarget.value.length > 4){
  	tooltip.innerHTML = "Exceeded length of 4";
    tooltip.style.display = "block";
    input.style.border = "3px solid red";
  }
  else if(e.currentTarget.value.length <= 4) {
  tooltip.innerHTML = "";
    tooltip.style.display = "none";
    input.style.borderColor = "1px solid black";
  }
})