Hey everyone! I've created a script that restricts textboxes to allow only decimal numbers. Take a look at the code snippet below:
function onlyDecimal(evt) {
if (!(evt.keyCode == 46 || (evt.keyCode >= 48 && evt.keyCode <= 57)))
return false;
var parts = evt.srcElement.value.split('.');
if (parts.length > 2)
return false;
if (evt.keyCode == 46)
return (parts.length == 1);
if (parts[0].length >= 15)
return false;
if (parts[1].length >= 3)
return false;
}
<asp:TextBox ID="txtDecimal" runat="server" OnKeyPress="return onlyDecimal(event)" />
As it stands, this script only allows inputs like:
1.000
12.000
123.123
However, I'm looking to enhance it to accept inputs like 1234.123,12345.123
and beyond. Can someone lend a hand?
Another issue I've encountered is that when I try to edit the decimal part after entering a number like 12.123
, it doesn't allow me to edit the value until I clear the input. Any advice on how to address this?