I have a RegularExpressionValidator control in my page & have a Global Public Regex variable in my code behind which has correct ValidationExpression & Option & TimeSpan. Bellow is my codeBehind code :
public partial class Index : System.Web.UI.Page
{
public Regex regex;
protected void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
if (!IsPostBack)
{
regex = new Regex("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*", RegexOptions.Singleline, TimeSpan.FromSeconds(5));
}
}
}
I want to add it to my page control. it identefy it but validation Error alway being shown and it's not working Even when i enter right format. I have tried to type. first one have no error but false react. the second one with page erro that cause the page to not get loaded.
The 1st type code in WebPage is below:
<asp:RegularExpressionValidator ID="REV" runat="server" Text="Incorrect Format" ForeColor="Red" ControlToValidate="txt1" ValidationExpression="<%# regex %>" Display="Dynamic" />
The 2nd type code in WebPage is below:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" Text="Incorrect Format" ForeColor="Red" ControlToValidate="txt1" ValidationExpression="<%# regex.Match(txt1.Text) %>" Display="Dynamic" />
How can I solve this problem. Thank You all so much :)