jQuery: Validate numeric values for input field

This is the function to validate for the number when a key is pressed to fill the input field.

HTML


<div class="wrapper">
    <form method="" name="" >
        <input type="text" value="" name="" class="inp_valid">
        <span id="num_validate">Please enter a valid number.</span>
    </form>
</div>



Javascript




    jQuery.fn.NumericOnly = function() {
        return this.each(function()
        {
            $(this).keydown(function(e)
            {
                var key = e.charCode || e.keyCode || 0;
                // allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY
                // home, end, period, and numpad decimal
                if ( key == 8 || key == 9 || key == 13 || key == 46 || key == 110 || key == 190 || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105)) {
                    jQuery('#num_validate').hide();
                    return true;
                }else {
                    jQuery('#num_validate').show();
                    return false;
                }

            });
        });
    };

   

jQuery(".inp_valid").NumericOnly();