Rishabh
Rishabh

Reputation: 299

Asp .net Validation controls

I have one text box and these asp validation controls on it.

     <asp:TextBox ID="txtMinLot" runat="server" CssClass="form-control" MaxLength="10" CausesValidation="false"> </asp:TextBox>


 <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtMinLot" ErrorMessage="Please enter min lot for Bidding" Font-Names="Arial" Font-Size="11px" Display="Dynamic" SetFocusOnError="True" ValidationGroup="check" ForeColor="Red"></asp:RequiredFieldValidator>


    <asp:RegularExpressionValidator ID="RegularExpressionValidator13" runat="server" ControlToValidate="txtMinLot" Display="Dynamic" ErrorMessage="Not a Valid number." Font-Size="11px" ForeColor="Red" SetFocusOnError="True" ValidationExpression="[0-9]*$" ValidationGroup="check" />


     <asp:RangeValidator ID="rvLot" ControlToValidate="txtMinLot" runat="server" CssClass="result" Display="Dynamic" SetFocusOnError="True" ErrorMessage="Min Quantity should be less than Total Quantity and more than 0" Font-Size="11px" ForeColor="Red" MinimumValue="1" MaximumValue="100"></asp:RangeValidator>

But as i type something in character both range validator as well as regular expression validator message is showing in the page. But I want to show only one message at a time

Upvotes: 1

Views: 291

Answers (2)

Zaigham Sarfaraz
Zaigham Sarfaraz

Reputation: 111

In this case when you want the value in txtMinLot to be an integer number between 1 to 100, you don't need a regularexpression validator at all. you simply need to use a requiredfieldvalidater and rangevalidator; just like you did but with one change:

<asp:RangeValidator Type="Integer" ID

Type="Integer" will make sure user doesn't enter real numbers with decimal points and will only enter integers

Upvotes: 1

Robert McKee
Robert McKee

Reputation: 21487

Use regular expression "[1-9][0-9]?|100" and remove the range validator.

Another option is just to use a style (CSS) to hide the additional error messages. The exact rule will depend on what version of the validators you are using, so I'm not even going to guess, but if you post the HTML that is generated, it should be easy.

Upvotes: 0

Related Questions