$("#user").keyup(function(e){
var regx = /^[A-Za-z0-9]+$/;
if (!regx.test('#user'))
{$("#infoUser").html("Alphanumeric only allowed !");}
);}
#user is a text input, and I want to diplay a warning if user enters anything except letters and numbers.
In the above case, the warning is present whatever is typed.
#useritself, not of the content/value of the element that have the iduser.!regx.test($(e).val())should suit your needs.