Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have used regular expression validator in asp.net for email validation. it is working in localhost perfectly but after upload the pages in server, regular expression validator is not working.after saving the details into database it shows "invalid email id". pls help

ASP.NET
<asp:TextBox ID="txtEmailid" runat="server" Width="180px" BorderColor="Black"
                                                             BorderStyle="Solid" BorderWidth="1px">
                                                         <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"                                                       ControlToValidate="txtEmailid" ErrorMessage="Invalid" ForeColor="#F04E23"
                                                             ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">


Code Behind

C#
protected void btnsave_Click(object sender, EventArgs e)
   {
       Page.Validate();


     if (txtMobileNo.Text == "")
       {
           lblErr.Text = "Enter the Mobile No";
           txtMobileNo.Focus();
           return;

       }
       else if (txtPhoneNo.Text == "")
       {
           lblErr.Text = "Enter the Phone No";
           txtPhoneNo.Focus();
           return;
       }
       else if (txtFax.Text == "")
       {
           lblErr.Text = "Enter the Fax No";
           txtFax.Focus();
           return;
       }
       else if (txtEmailid.Text == "")
       {
           lblErr.Text = "Enter the Email Id";
           txtEmailid.Focus();
           return;
       }

       else if (txtAddress.Text == "")
       {
           lblErr.Text = "Enter the Address ";
           txtAddress.Focus();
           return;
       }


       else
       {

               sales.Save();
               lblErr.Text = "Details Saved Successfully";
               GridBindData();
               Clear();

           }


   }
Posted
Updated 17-Apr-13 11:10am
v4
Comments
PrashantSonewane 17-Apr-13 6:55am    
Can you give some code of your html file where reg. expression is?
satsri46 17-Apr-13 7:15am    
<asp:TextBox ID="txtEmailid" runat="server" Width="180px" BorderColor="Black"
BorderStyle="Solid" BorderWidth="1px" >
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmailid" ErrorMessage="Invalid" ForeColor="#F04E23"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">


Code Behind

protected void btnsave_Click(object sender, EventArgs e)
{
Page.Validate();


if (txtMobileNo.Text == "")
{
lblErr.Text = "Enter the Mobile No";
txtMobileNo.Focus();
return;

}
else if (txtPhoneNo.Text == "")
{
lblErr.Text = "Enter the Phone No";
txtPhoneNo.Focus();
return;
}
else if (txtFax.Text == "")
{
lblErr.Text = "Enter the Fax No";
txtFax.Focus();
return;
}
else if (txtEmailid.Text == "")
{
lblErr.Text = "Enter the Email Id";
txtEmailid.Focus();
return;
}

else if (txtAddress.Text == "")
{
lblErr.Text = "Enter the Address ";
txtAddress.Focus();
return;
}


else
{

sales.Save();
lblErr.Text = "Details Saved Successfully";
GridBindData();
Clear();

}


}
codeninja-C# 17-Apr-13 7:46am    
Hi,
1. your regex expression is correct so, try to check your input email address.
2. If it doesn't work in client side, check with page side validation in c#.
3. If page side validation works fine, try to create new text box with new regex validation control
--SJ
Karthik Harve 17-Apr-13 6:57am    
did you checked the validation group if any ?
satsri46 17-Apr-13 7:18am    
I didn't use any javascript. I used RegularExpression validator control which is in asp.net

1 solution

The validation control uses javascript or something on the client side.

You should make a validation group, called form or something, and add the validation group attribute to the textbox, validation control and submit button, and add causes validation to the submit button.

On the code behind, I think it's, I write in VB, so it's a little different in CS

If Page.validation then

end if

Clear your browser cache and test it. Check your version of asp.net on the server, it may be out of date, or IIS web server may have to be restarted, it may be caching html, and the cache didn't update.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900