Use o patterns para o HTML 5.
Exemplo:
<code> <input type="text" pattern="^[a-zA-Z0-9]+$" /> </code>
<input type="text" pattern="^[a-zA-Z0-9]+$" />