$(\"#user\").keyup(function(e){
var regx = /^[A-Za-z0-9]+$/;
if (!regx.test(\'#user\'))
{$(\"#infoUser\").html(\"Alphanumeric only allowed !\");}
);}
<
You must test with #user element value not '#user' string
$("#user").keyup(function(e){
var regx = /^[A-Za-z0-9]+$/;
if (!regx.test($('#user').val())) // .
{$("#infoUser").html("Alphanumeric only allowed !");}
);}