$(\"#user\").keyup(function(e){ var regx = /^[A-Za-z0-9]+$/; if (!regx.test(\'#user\')) {$(\"#infoUser\").html(\"Alphanumeric only allowed !\");} );} <
function isNotAlphanumeric(){ return (! val.match(/^[a-zA-Z]+$/)) //return val.match(/^[a-zA-Z0-9]+$/) ? false : true; }
so if val is alpha numeric it return false. So based on returned value take appropriate action. You can call this method on key up event.