144
rated 0 times
[
145]
[
1]
/ answers: 1 / hits: 18617
/ 11 Years ago, wed, march 6, 2013, 12:00:00
Here is a fiddle to start - http://jsfiddle.net/zuVpx/1/
Javascript code:
<script>
function validate(e) {
var regex = new RegExp([a-zA-Z0-9]);
var key = e.keyCode || e.which;
key = String.fromCharCode(key);
if(!regex.test(key)) {
e.returnValue = false;
if(e.preventDefault) {
e.preventDefault();
}
}
}
</script>
HTML code:
<input type=text onkeypress=validate(event) />
I want only characters and numbers. Keys like backspace, delete, capslock and arrowkeys etc should work.
Thanks in advance.
More From » jquery