Here is one BUG.
First input ID.
When I write 45, the comma replaces it with a dot. Then I can write 45........ but allow only one dot. Code .length === 2) { First input is done IF bug fixed :)
Second input ID
And second input like this if you look demo: https://jsfiddle.net/alumic/exj15dfy/8/
This script work almost but here no work dot (.)
Here is comma first and cant delete.
Accepts -9 -9.99
Do not accept 9-. 9.- -.9
Very-very Thanks if can help :)
<html>
<head>
<meta charset="utf-8" />
<title></title>
<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(',', '.');
}
</script>
</head>
<body>
<input id="number" onkeypress="return IsNumeric(event);" onkeyup="ReplaceComma(this)"
ondrop="return false;" onpaste="return false;">
</body>
</html>