I want to keep the input value limited to number(including -ve integers) and limit decimals to 2 digit.
Accept:
22.33; -123.45; 0.22
Reject:
-123.000123; --123.000123; -123-23.12; --23-1.00
I'm using this
<input id="restricted" type="text" class="form-control" placeholder="00.00" onkeypress="return isNumberKey(evt,this)"/>
function isNumberKey(evt, element) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) && !(charCode == 46 || charcode == 8))
return false;
else {
var len = $(element).val().length;
var index = $(element).val().indexOf('.');
if (index > 0 && charCode == 46) {
return false;
}
if (index > 0) {
var CharAfterdot = (len + 1) - index;
if (CharAfterdot > 3) {
return false;
}
}
}
return true;
}
I dont want it to validate. I want it not accept other than integers and limit it to 2 digit after "."