Check if character is number?

前端 未结 22 684
误落风尘
误落风尘 2020-12-03 00:29

I need to check whether justPrices[i].substr(commapos+2,1).

The string is something like: \"blabla,120\"

In this case it would check whether \'0

22条回答
  •  攒了一身酷
    2020-12-03 00:54

    you can either use parseInt and than check with isNaN

    or if you want to work directly on your string you can use regexp like this:

    function is_numeric(str){
        return /^\d+$/.test(str);
    }
    

提交回复
热议问题