wanna check if string contains number (float or integer)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Kypriotis
    New Member
    • Mar 2011
    • 37

    #1

    wanna check if string contains number (float or integer)

    in a forum found this
    Code:
    function isNumber(n) {
      return !isNaN(parseFloat(n)) && isFinite(n);
    }
    as the best solution, is it? Plus why both !isNAN and isFinite() are used together, which weaknesses each other covers?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I don’t know if it is the best solution, but it certainly is a good one.

    see https://developer.mozilla.org/en/Jav..._Objects/isNaN why the use of isFinite is required.

    Comment

    Working...