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