Check if character is number?

前端 未结 22 706
误落风尘
误落风尘 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:51

    This seems to work:

    Static binding:

    String.isNumeric = function (value) {
        return !isNaN(String(value) * 1);
    };
    

    Prototype binding:

    String.prototype.isNumeric = function () {
        return !isNaN(this.valueOf() * 1);
    };
    

    It will check single characters, as well as whole strings to see if they are numeric.

提交回复
热议问题