I need a regex which matches an inputs like:
1234.789
12
123.02
that is, maximum 4
digits on the left side of .
and maximum 3
on right of .
here is what I have tried.
i = 0;
$(document).ready(function(e){
$("input").keypress(function(e){
var patt = new RegExp("^[0-9]{1,4}(?:\.[0-9]{0,3})?$");
var val = this.value + e.key;
debugger;
if (!patt.test(val)){
e.preventDefault();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Enter your name: <input type="number">