Validate textbox only numeric or number in JQuery

Validate textbox only numeric or number in JQuery

If you want to validate text for for entering only number or numeric values then here is jquery/javascript code.(Tested)

Below Is for All text box on page

$(document).ready(function () {
            $("input[type='text']").keypress(function (e) {
                if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                    return false;
                }
            });
        });

And if you want to apply on specific text box then you can use selecter ID or class as you wish.



$(document).ready(function () {
            $("#txtbox1").keypress(function (e) {
                if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                    return false;
                }
            });
        });