Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a form that has three textboxes on it. The user can enter a negative number and the textboxes does the calculations with it but when the user clicks on the submit button the validation fires. How can I get the validation to work and pass the negative numbers?

ASP.NET
<td>
                <asp:TextBox ID="TextBoxTA" runat="server" Width="180px">0</asp:TextBox>
                <asp:Label ID="lblreq20" runat="server" CssClass="style52" Text="*"></asp:Label>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator33" 
                    runat="server" ControlToValidate="TextBoxTA" CssClass="style45" 
                    ErrorMessage="You Must Enter A Number For This Field" ForeColor="Red" 
                    ValidationExpression="^\d+$"></asp:RegularExpressionValidator>
            </td>
Posted

If you use following regular expression you can allow the following formats
Expression :
^-?\d*\.?\d+$

allowed formats are like
-1, .1, -.1, 0.1,-0.1
 
Share this answer
 
It should be:
^[-]?\d+$

You need a "[-]" at the beginning to accept negative sign, and "[-]?" means zero or one negative sign.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900