Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

isNaN int? 1

Status
Not open for further replies.

irate

Programmer
Jan 29, 2001
92
GB
i currently have the following code:

if (isNaN(theForm.askingprice.value))
missing += "Price must be a number\n"

if (missing != "")
{
alert("You must fill in all the required fields without errors.\n\nYou missed the following sections:\n\n"+missing);
return false;
}
else
return true;


I was wondering if there is some sort of isInt function that i could use to check to see if the user entered a integer. So for example if they put 5 it would be ok but if they put 5.5 it would alert them of the error.
 
Hi, this may help you:

<script language=javascript>
var a=theForm.askingprice.value;
var b=Math.floor(a);
if (a%b==0) alert('OK'); else alert('Not Integer');
</script>

Sergio M. Netto
 
thankyou that is perfect.
now using this code:


if (theForm.askingprice.value == &quot;&quot;)
missing += &quot;\n* Asking Price\n&quot;;
if (isNaN(theForm.askingprice.value))
missing += &quot;\n* Asking Price must be a number\n&quot;
var askingpricea=theForm.askingprice.value;
var askingpriceb=Math.floor(askingpricea);
if (theForm.askingprice.value != &quot;&quot; && askingpricea%askingpriceb!=0)
missing += &quot;\n* Asking Price must be an integer\n&quot;
if (theForm.askingprice.value != &quot;&quot; && theForm.askingprice.value < 1)
missing += &quot;\n* Asking Price must be positive\n&quot;

:)
:-D
LOL


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top