<input id='test'> <script> test.oninput = function () { var reg = /^\d{1,4}(\.\d{0,2})?$/, val = this.value; if(!reg.test(val)) this.value = val.slice(0,-1); } </script>