Results 1 to 6 of 6

Thread: help with isNaN

  1. #1
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default help with isNaN

    I have this simple check but for some reason javascript is not seeing the var as a number even when it is a number. This is the code:


    if(isNaN(usagePos1)){

    Process(usagePos1);


    } else {

    alert(usagePos1+" is not a numeric value! Please enter a numeric value!");
    return false;

    }
    usagePos1 is actually passed as a parameter from a split()

    Any ideas?
    Last edited by leocrawf; Jun 20, 2011 at 03:38 AM.
    "...men are that they might have joy."
    Nephi

  2. #2
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    As far I know, the result from a split() is always an array and passing an array to the isNaN() function would most likely give you some incorrect results. Might want to loop through the array usagePos1, passing each value through isNaN().
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  3. #3
    Join Date
    Jan 2007
    Posts
    164
    Rep Power
    18

    Default

    first line should be : if(!isNaN(usagePos1)) since isNaN returns false when usagePos1 is a number.

  4. #4
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Thank you all so much for your replies. I will look into it.
    "...men are that they might have joy."
    Nephi

  5. #5
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Quote Originally Posted by hassanvoyeau View Post
    first line should be : if(!isNaN(usagePos1)) since isNaN returns false when usagePos1 is a number.
    Oh yeah, that's right. isNaN is already in the negative. If isNaN is true, that means it's Not-a-Number. If it's false, that mean's it IS a number. That one slipped me. But my excuse is, it was 4am in the morning. :P
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  6. #6
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Thank you all it works perfectly.
    "...men are that they might have joy."
    Nephi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •