Back to blog

OnKeyUp Fix Alphanumerical Chars

When you have an html form and you want only alphanumerical [a-z0-9] chars in your input, you can use this…

When you have an html form and you want only alphanumerical [a-z0-9] chars in your input, you can use this small piece of code in the onkeyup attribute. It will strip non alphanumerical characters while they are typed in a input text box.

<form>
<input type='text' onkeyup="this.value = this.value.replace(/[^a-z0-9]/gi,"");" />
</form>

Canonical URL