Yum a lot of confused in the morning, should it be less or more than `
it may take a value less than "99999"
I think you yourself answered this ... But it is valid when it is less . Therefore, the following is not true:
}elseif($("#seats").val() < 99999){ alert("Not a valid Number"); }else{
You say if it is less than 99999, then it is invalid . You want to do the opposite:
}elseif($("#seats").val() >= 99999){ alert("Not a valid Number"); }else{
Also, since you have $("#seats") twice, jQuery should look for the DOM twice. You really have to store the value, or at least the DOM element in a variable. And some more of your code doesn't make much sense, so I'm going to make some assumptions and all together:
var seats = $("#seats").val(); var error = null; if (seats == "") { error = "Number is required"; } else { var seatsNum = parseInt(seats); if (isNaN(seatsNum)) { error = "Not a valid number"; } else if (seatsNum >= 99999) { error = "Number must be less than 99999"; } } if (error != null) { alert(error); } else { alert("Valid number"); }
Here's a working example: http://jsfiddle.net/LUY8q/
Nelson roothermel
source share