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…

November 10, 2009

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>

Author

I'm a software engineer, an everyday web developer and a maker. I usually build sites with PHP, within or without WordPress. I build Internet of Things with Arduino and ESP8266. I'm the founder of Rockit.it and Dailybest.it and I'm actually the Chief Technical Officer of Better Days web agency.

Recommended

Unobtrusive javascript to add an overlay banner

If you have to add an overlay to a site, here is a fast way to do it with an…

November 7, 2011

PHP parse url, mailto, and also twitter’s usernames and arguments

This small function receive a text as input and returns an html text with links if the source text contains…

March 10, 2010

How to capture enter key pressed in a form (JavaScript)

Suppose you have a login form and you want to send the form when user press enter on his keyboard…

February 16, 2010

Fix html tags, close tags, repair bad quotes and more

This class can solve many problems coming from user generated html content or to fix html content before making some…

February 3, 2010

Add Internet Explorer class to body to detect old browser

When you have clients that still uses an old browser, you need to handle it. This javascript function detects the…

February 27, 2017

Highlight text for search results in PHP

Useful code to highlight text occurences in search results or in a text. How to highlight text in a string…

September 2, 2016