Yo uso este...
Código PHP:
function OnlyCharAndNum(tfield) {
var valid = " abcdefghijklmnopqrstuvwxyz0123456789";
var ok = "yes";
var temp;
for (var i=0; i<tfield.value.length; i++) {
temp = "" + tfield.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Error. Caracteres no aceptados");
tfield.focus();
}
}