JSFiddle - React, Tailwind, and code Playground

HTML

<input class="btn-input order-count" type="text" >

JavaScript

var $maxLen = 2;
var $curLen=0;
$('body').on('click keypress', '.btn-input', function(key) {
  var $this = $(this);  
  var curVal = $this.val();
  if (key.charCode < 48 || key.charCode > 57) return false;
  $curLen = $this.val().length;
  console.log($curLen, '>', $maxLen);
  if ( $curLen > $maxLen){
  	return false
  } else{
  	$this.val(curVal);
  }
    
});