Limit number between Min and Max value in multiple HTML TextBox using jQuery

kevinf
 
on Jun 28, 2022 11:13 PM
Sample_454213.zip
673 Views

Hi

I have 20 TextBoxes and the user keys in numbers.

How can I prevent any numbers being entered less than 0 or greater than 999.99.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jun 28, 2022 11:22 PM
on Jul 01, 2022 04:27 AM

Hi kevinf,

Use JavaScript to validate the TextBoxes. Assign a common class to each TextBox.

Then using the class selector check the value of the TextBox with in the range.

Check the example.

HTML

<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <input type="text" class="validate" />
    <input type="text" class="validate" />
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.validate').change(function () {
                var number = $(this).val();
                if ((isNaN(number))) {
                    alert('Invalid number');
                    return false;
                }
                if (parseFloat(number) >= 0 && parseFloat(number) <= 999.99) {
                    return true;
                } else {
                    alert('Enter number between 0 to 999.99');
                    return false;
                }
            });
        });
    </script>
</body>
</html>

Demo