CompareValidator not firing

josephjohn100

Member
Joined
Nov 8, 2012
Messages
8
Programming Experience
3-5

I'm using the following code to check whether the text box accepts only number. but this is not firing ?

<td
class="Content" style="background-color: #e4ecee"> Claim #:
<asp:TextBox ID="txtClaimNumber" runat="server" ></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" ControlToValidate="txtClaimNumber" CssClass="error-text" Display="None" EnableClientScript="false" ErrorMessage="Claim # should contain only numbers" Operator="DataTypeCheck" runat="server" Type="Integer">*</asp:CompareValidator>
</td>
 
Hi,

Try using a RegularExpression validator instead. i.e:-

HTML:
<asp:RegularExpressionValidator id="RegularExpressionValidator1" 
   ControlToValidate="txtClaimNumber" 
   ValidationExpression="\d+" 
   Display="Static" 
   EnableClientScript="true" 
   ErrorMessage="Please enter numbers only" 
   runat="server"/>

Hope that helps.

Cheers,

Ian
 
Do you mean that it doesn't validate at all or is it maybe only when the TextBox is empty? If it's the latter then that is the expected behaviour.
MSDN said:
If the input control is empty, no validation functions are called and validation succeeds. Use a RequiredFieldValidator control to require the user to enter data in the input control.
 
Back
Top