Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
good morning

in one page i have a textbox for name and a button.

for example if i enter any number or special character in the textbox and press the button,the page should be redirected to another page and show any exception there.

C#
protected void btnsubmit_Click(object sender, EventArgs e)
   {
       if (txtname.Text = "")
       {

       }

       else
       {
           Response.Redirect("Exceptions2.aspx");
       }


   }


please help me.
Posted
Updated 6-Jun-13 18:17pm
v3
Comments
Rockstar_ 7-Jun-13 0:21am    
You mean ur textbox accepts only alphabets? if user enters numbers or special symbol then redirect to exceptionpage.aspx and display the error message? right..
Nandakishore G N 7-Jun-13 0:43am    
first change the if condition you are not comparing you are assigning values.i.e., replace "=" with "==" and check

1 solution

Try this:
C#
protected void btnsubmit_Click(object sender, EventArgs e)
{
    Match match = Regex.Match(txtname.Text, @"(?i)^[a-z]+");
    if (match.Success)
    {
    
    }
    else
    {
        Response.Redirect("Exceptions2.aspx");
    }
}

Also I would suggest you to check : C# Regular Expressions Cheat Sheet[^].


--Amit
 
Share this answer
 

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