new RegExp(/^\d*(\.\d{0,2})?$/, 'g');
<!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> <style type="text/css"> </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> $(function() { var oldVal = ''; $('body').on('input', '.input-class', function(e){ var newVal = this.value; var regex = new RegExp(/^\d+(\.\d{0,2})?$/, 'g'); if(newVal && !regex.test(newVal) ){ this.value = oldVal; } oldVal = this.value; }); }); </script> </head> <body> <input type="text" class="input-class"> </body> </html>