I want to check if nickname contains only numbers and letters. It cant contain anything else. My current code is not working because as soon as I type in atleast one legal lettrer, the entire string evaluates to true every time I check, no matter how many illegal characters it contains. What am I doing wrong here.
My code (Ignore the commented part):
$(function(){
$("#nickname").keyup(function(event){
var validate = new RegExp("[A-Za-z0-9]"); // All letters and digits, including "_"
var nickname = $(this).val();
if(!validate.test(nickname)){
console.log("Did not validate");
$("#message-area").html("Kasutajanimi koosneb lubamatutest sümbolitest. Kasutajanimi võib koosnema tähtedest, numbritest ja alakriipsudest ('_')");
}
/*
$.ajax({
type: "POST",
url: "login.php",
data: {"nickname" : nickname},
dataType: "json",
success: function(data){
$("#message-area").html(data.message);
if(data.available){
$("#choose-name").val('Sisene');
}else{
$("#choose-name").val('Kontrolli');
}
}
});*/
});
});