Check if character is number?

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

    var Is = {
        character: {
            number: (function() {
                // Only computed once
                var zero = "0".charCodeAt(0), nine = "9".charCodeAt(0);
    
                return function(c) {
                    return (c = c.charCodeAt(0)) >= zero && c <= nine;
                }
            })()
        }
    };
    

提交回复
热议问题