http://jsbin.com/cunejafehe/edit?html,js,console,output
var reg = /^[a-zA-Z\d\s\-'#(),"]*$/;
   
function myFunction(e){
  console.log(e.value);
  if(reg.test(e.value))
   {
     return false;
   }
}
<input onkeyup="myFunction(this)" type="text">
I wonder why above code doesn't work, what I want to do is allow only these character to be in the input : a-z and 1-9 including 0, and these character -'#(),"
return true;instead offalse?<input onkeypress="checkInput(event)" type="text">andvar reg = /[a-zA-Z\d\s\-'#(),"]/; function checkInput(e) { var ok = reg.test(String.fromCharCode(e.charCode)); if (!ok) e.preventDefault(); }