Check if character is number?

前端 未结 22 679
误落风尘
误落风尘 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 01:05

    You could use comparison operators to see if it is in the range of digit characters:

    var c = justPrices[i].substr(commapos+2,1);
    if (c >= '0' && c <= '9') {
        // it is a number
    } else {
        // it isn't
    }
    

提交回复
热议问题