checking if number entered is a digit in jquery

前端 未结 10 1721
遥遥无期
遥遥无期 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 01:42

    With jQuery's validation plugin you could do something like this, assuming that the form is called form and the value to validate is called nrInput

    $("form").validate({
                errorElement: "div",
                errorClass: "error-highlight",
                onblur: true,
                onsubmit: true,
                focusInvalid: true,
                rules:{
                    'nrInput': {
                        number: true,
                        required: true
                    }
                });
    

    This also handles decimal values.

提交回复
热议问题