Allow only numeric input in textbox using jQuery

Allow only numeric input in textbox using jQuery

HTML

<span>Float</span>
<input type="text" name="numeric" maxlength='50' class='allownumericwithdecimal'>
<div>Numeric values only allowed  (With Decimal Point) </div>    
    <br/>   <br/>   <br/>
    
 <span>Int</span>
<input type="text" name="numeric" class='allownumericwithoutdecimal'>
<div>Numeric values only allowed  (Without Decimal Point) </div>

JavaScript

$(".allownumericwithdecimal").on("keypress keyup blur",function (event) {
            //this.value = this.value.replace(/[^0-9\.]/g,'');
     $(this).val($(this).val().replace(/{2}[^0-9\.]/g,''));
            if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
                event.preventDefault();
            }
        });

 $(".allownumericwithoutdecimal").on("keydown",function (event) {  
   var regex = "/^(0[1-9]|1\d|2[0-3]):([0-5]\d):([0-5]\d)$/";
   var _event = event || window.event;
   var key = _event.keyCode || _event.which;
   console.log(key);
   key = String.fromCharCode(key);
   console.log(key);
   if(regex.test(key)) {
     _event.returnValue = false;
     if (_event.preventDefault)
       _event.preventDefault();
   }
 });

$('#test').inputmask('Regex', { 
    regex: "^[0-9]{2}:[0-5][0-9]:[0-5][0-9]$"
});