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.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

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

Back to top button