Jquery allow only number up to 10 digit


In this blog, we will see how can allow up to 10 digits numbers, basically this script will help you with the number box input.

I will use keypress event so that I can capture the things on keypress, and I will also jquery attr method to add the min attribute by using the jquery.

Below is the HTML code.

<input type ="number" class="allow-only-number"/> 

Below is the script which helps you to allow only 10 digit numbers to the input field, it will also block negative and e keywords.

$(".allow-only-number").keypress(function (e) {
        $(".allow-only-number").attr("min", "10");
            var valueLength = this.value.length;
            if (valueLength == 10) {
                return false;
            var kk = e.which;
            if (kk < 48 || kk > 57)

I hope the above small query will help you to resolve your issue, happy coding.

Do you want to hire us for your Project Work? Then Contact US.
Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *