i have a function that accepts only integer inputs from a textbox. after calling the parseInt method on it, it still accepts integers with strings after it. i'm wondering how to implement a regex to filter out inputs that contain string. here is my code.
var validate = function() {
$("#newgame").click(function() {
$("label").text("What's your guess.");
$("#guess").val("");
})
$("#submitguess").click(function() {
initguess = parseInt($("#guess").val(), 10);
if ( isNaN(initguess) || initguess > 100 || initguess < 0 || typeof initguess === "string") {
$("label").text("Enter a valid format.");
}
else {
if (initguess === number) {
$("label").text("Waoh! You guessed right.");
$("#submitguess").hide("slow");
// displaybar(diff);
}
else {
$("label").text("You are getting hot.");
// displaybar(diff);
feedback(initguess);
}
}
// var diff = (100 - Math.abs(number - initguess));
// displaybar(diff);
});
}