In Typescript, How to check if a string is Numeric

前端 未结 10 1160
耶瑟儿~
耶瑟儿~ 2020-12-02 11:38

In Typescript, this shows an error saying isNaN accepts only numeric values

isNaN(\'9BX46B6A\')

and this returns false because parseF

10条回答
  •  清歌不尽
    2020-12-02 12:31

    function isNumber(value: string | number): boolean
    {
       return ((value != null) &&
               (value !== '') &&
               !isNaN(Number(value.toString())));
    }
    

提交回复
热议问题