newbie: isNaN

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
tabutcher
Forum Newbie
Posts: 20
Joined: Fri Aug 21, 2009 7:10 am

newbie: isNaN

Post by tabutcher »

hello,
basically what I want is to have a while loop that will prompt the user continuously until he/she inputs a number. I entered some test data and found that if I put for example '1a' it will except it.
thank you in advance

Briefly:
I prompt for a value
check to see if value is only two digits long
convert string to int
check value is a number
Below is my code:

Code: Select all

 do{    num1 = prompt("Enter number 1", "");    if(num1.length > 2)    {        valid = false;    }    else    {        valid = true;    }    num1 = parseInt(num1);}while(isNaN(num1) || valid == false); 
urooj786
Forum Newbie
Posts: 12
Joined: Mon Nov 09, 2009 11:56 pm

Re: newbie: isNaN

Post by urooj786 »

isNaN function is used only to check that entered value is a numericor not......
Post Reply