Hello!
Here is two (2) BUG.
1) Allow only one dot (.) but if I typing -9,9,9 then results is 9.9.9
2) If I hold down the comma button on the keyboard then results is -9.,,,,
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
var specialKeys = new Array();
specialKeys.push(8);
specialKeys.push(9);
specialKeys.push(46);
specialKeys.push(36);
specialKeys.push(35);
specialKeys.push(37);
specialKeys.push(39);
function IsNumeric(e) {
if (e.keyCode === 46 && e.target.value.split('.').length === 2) {
return false;
}
var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
return ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90)
|| keyCode == 32 || keyCode == 44 || keyCode == 46
|| (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode));
}
function ReplaceComma(ele) {
if (ele.value.indexOf('.') == 0) {
ele.value = ele.value.replace('.', '');
}
if (ele.value.indexOf(',') == 0) {
ele.value = ele.value.replace(',', '');
}
ele.value = ele.value.replace(',', '.').replace('..', '.');
}
function doCheck(id, evt) {
var temp = parseInt($(id).val());
if (isNaN(temp)) {
$(id).val('-');
}
$(id).val($(id).val());
}
</script>
</head>
<body>
<input type="text" value="-" maxlength=7 id="fmargin" onkeypress="return IsNumeric(event);"
onkeyup="ReplaceComma(this);doCheck('#fmargin', event);">
</body>
</html>