JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" id="passcode">

JavaScript

$(function() {
  $('#passcode').on('keypress', function(e) {
      var key = String.fromCharCode(!e.charCode ? e.which : e.charCode);
      if (!/^[A-Z0-9]+$/i.test(key)) {
          e.preventDefault();
      }
  })
});