Use
^-*[0-9]+\.?[0-9]*$
As you have improved the question, I see you are using
JavaScript
codes to validate. You don't need it. Better you use a
RegularExpressionValidator
.
I used the following code. You may try something similar:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ControlToValidate="TextBox1" ID="RegularExpressionValidator1" ValidationExpression="^-*[0-9]+\.?[0-9]*$" runat="server" ErrorMessage="Invalid input."></asp:RegularExpressionValidator>
I've tested, this is working. Please let me know if there is anything further problem.