JSFiddle - React, Tailwind, and code Playground

HTML

<script src="//ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.6.2.js"></script>    
<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
<input type="number" maxlength="4">

JavaScript

$(function() {
  if (Modernizr.inputtypes.number) {
  	$('input[type=number]').keypress(function(e) {
    	var $this = $(this),
      		maxlength = $this.attr('maxlength'),
      		length = $this.val().length;
            
      if (length >= maxlength)
      	e.preventDefault();
    });
  }  
});