-
Texbox - CompareValidate
I have 2 textboxes like
NoDays_____ SanctionedDays____
NoDays Default value=5. NOw i want to Compare the SanctionedDays like (san.days < NoDays) and sanctionDays Textbox has to allowe only Numeric Data.
For this I have writeen a validaions as follows.
My Question is Once the RegularExpre.. validation is satisfy then only it has to go Compare validaion. Because when i enter SanctionedDays="AA" it is displaying both error messages..?
Texbox Code
Code:
<Asp:Textbox id="txtNoDays" BackColor="Gainsboro" ReadOnly="True" Runat="server" size="10"/>
<Asp:Textbox id="txtSanDays" Runat="server" size="10" MaxLength="3"/>
my Validation Code
Code:
<asp:CompareValidator id="comp1" ControlToValidate="txtNoDays" ControlToCompare = "txtSanDays" Type="String" Operator="GreaterThanEqual" Text="Sanctioned days should be less than days requested!" runat="server"/>
<asp:RegularExpressionValidator ControltoValidate="txtSanDays" Display="Dynamic" ErrorMessage="Enter Numeric data" ValidationExpression="\d" Runat="Server" />
How to do this? how to validate one after one?
-
Your controls will fail on both counts if you enter "AA" because it is not a number and it can't be calculated to be greater than or equal to the other control. You can leave out the regular expression validator because the compare validator will return an error if the SanctionedDays is not a number.
-
But i need to maintain both. How will u do?
-
I still don't understand the need for both. If this validator:-
<asp:CompareValidator id="comp1" ControlToValidate="txtNoDays" ControlToCompare = "txtSanDays" Type="String" Operator="GreaterThanEqual" Text="Sanctioned days should be less than days requested!" runat="server"/>
returns true then the Sanctioned days has a number in it. Checking it a second time with a regular expression validator is unecessary. Perhaps I'm misunderstaning you.