checking if number entered is a digit in jquery

前端 未结 10 1735
遥遥无期
遥遥无期 2020-12-01 01:19

I have a simple textbox in which users enter number.
Does jQuery have a isDigit function that will allow me to show an alert box if users ente

10条回答
  •  既然无缘
    2020-12-01 02:02

    String.prototype.isNumeric = function() {
        var s = this.replace(',', '.').replace(/\s+/g, '');
    return s == 0 || (s/s);
    }
    

    usage

    '9.1'.isNumeric() -> 1
    '0xabc'.isNumeric() -> 1
    '10,1'.isNumeric() -> 1
    'str'.isNumeric() -> NaN
    

提交回复
热议问题