HTML
<input type="text" onkeypress="avoidSplChars(event)" >JavaScript functionfunction avoidSplChars(e) {
e = e || window.event;
var bad = /[^\sa-z\d]/i,
key = String.fromCharCode(e.keyCode || e.which);
if (e.which !== 0 && e.charCode !== 0 && bad.test(key)) {
e.returnValue = false;
if (e.preventDefault) {
e.preventDefault();
}
}
}Hope this helps!!