Allow only numeric (0-9) in inputbox | jQuery?

There is no native jQuery implementation for allow numbers and decimal only in Textbox, but you can filter the input values of a Textbox with the following onlyNumeric function. This function suppports backspace, tab, delete, enter, arrows, numbers and keypad numbers only.
jQuery.fn.onlyNumeric = function() { return this.each(function() { $(this).keydown(function(e) { var key = e.charCode e.keyCode 0; return ( 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 numbers only textbox Full SOurce | jQuery
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script> $(document).ready(function(){ jQuery.fn.onlyNumeric = function() { return this.each(function() { $(this).keydown(function(e) { var key = e.charCode e.keyCode 0; return ( key == 8 key == 9 key == 13 key == 46 key == 110 key == 190 (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105)); }); }); }; $("#input-1").onlyNumeric(); }); </script> </head> <body> <input type="text" id="input-1"> </body> </html>

Allow numeric values only | JavaScript

You can use the following JavaScript code for allow numeric values only.
<input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');" />
run this source code Browser View

Allow numeric values only | JavaScript

Full Source | JavaScript
<!DOCTYPE html> <html> <body> <h2>Allow numeric values only | JavaScript</h2> <input type="text" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');" /> </body> </html>