Edit in JSFiddle

  <form action="" method="get">
    <input type="text" pattern="\d{2,4}" title="半角数字2~4桁" />
  </form>