An improved isNumeric() function?

前端 未结 7 1607
轮回少年
轮回少年 2021-02-01 14:00

During some projects I have needed to validate some data and be as certain as possible that it is javascript numerical value that can be used in mathematical operations.

7条回答
  •  面向向阳花
    2021-02-01 14:43

    How about:

    function isNumber(value) {
      value = Number(value);
      return typeof value === 'number' && !isNaN(value) && isFinite(value);
    }
    

提交回复
热议问题