Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Testing Through RegularExpressionValidator control:

XML
<asp:TextBox ID="TextBox1" runat="server"
    ValidationGroup="Regex"></asp:TextBox>
&nbsp;
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
    ControlToValidate="TextBox1" ErrorMessage="Invalid"
    ValidationExpression="[0-9]{0,5}" ValidationGroup="Regex"></asp:RegularExpressionValidator>
 <asp:Button ID="btnTestRegex" runat="server" Text="Valid Or Not?"
    ValidationGroup="Regex" />


Input:
TextBox1.Text = "1a";
Output:
Invalid.
-------------------------------******---------------------------------
Through Coding :
XML
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                            &nbsp;&nbsp;
                            <asp:Label ID="lblValid" runat="server" Text="Valid" Visible="false"></asp:Label>
                            &nbsp;&nbsp;
                            <asp:Label ID="lblInvalid" runat="server" Text="Invalid" Visible="false"></asp:Label>
                            &nbsp;&nbsp;
                            <asp:Button ID="Button3" runat="server" onclick="Button2_Click" Text="Button" />




Input:
TextBox1.Text = "1a";
Output:
Valid.

-----------------------------------*********----------------------------


Can anyone tell why this is behaving differently????
Posted
Updated 13-Apr-10 1:35am
v2

1 solution

I got the correct answer.
While using Regex though coding, we should specify the Format as
^[0-9]{0,5}$ instead of only [0-9]{0,5}.
The ^ carrot shows begning match
and $ dollar shows ending match.

============

From JSOP: Don't add an answer to your question. Use the Improve Answer button and change your original post. Also modify the question title by appending "[SOLVED]" this at the end.



 
Share this answer
 
v3

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