I am new to javascript. I want to validate input box value it should allow integer and decimal value (no alphabets), no limit for integer value but for decimal value it should accept only two digit after decimal point. https://jsfiddle.net/pnd6yvbj/ Example:
Allowed values in and decimal
1.1
1.12
233
Not allowed more than two decimal point
1.121
What I tried:
<input type="text" id="txt" value="" onkeyup = "check_val($(this).val())"/>
<script>
function check_val(val) {
var val = val.replace(^[1-9]\d*(\.\d+)?$,"");
$("#txt").val(val.split(' ').join(' '));
}
</script>