(Built-in) way in JavaScript to check if a string is a valid number

前端 未结 30 4046
-上瘾入骨i
-上瘾入骨i 2020-11-22 01:54

I\'m hoping there\'s something in the same conceptual space as the old VB6 IsNumeric() function?

30条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 02:32

    Try the isNan function:

    The isNaN() function determines whether a value is an illegal number (Not-a-Number).

    This function returns true if the value equates to NaN. Otherwise it returns false.

    This function is different from the Number specific Number.isNaN() method.

      The global isNaN() function, converts the tested value to a Number, then tests it.

    Number.isNan() does not convert the values to a Number, and will not return true for any value that is not of the type Number...

提交回复
热议问题