Click here to Skip to main content
15,898,374 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a text box field used for enter name . Now I want to validate this text box . I write the code as below
Regex nm = new Regex(@"^[a-z A-Z]{2,120}$");
if (!nm.IsMatch(textBox2.Text))
{
  Message Box.Show("Enter Your Name Correctly ", "Error");
}


It doesn't work correctly the coding is in C#.net
Posted
Updated 27-Oct-10 23:50pm
v2
Comments
Vigneshb6 28-Oct-10 8:37am    
Actually What Requirement u want it should not allow 1 that's it.
it is working fine, may be u have to change the expression for the correct o/p.

Try this.

Regex nm = new Regex(@"[a-z A-Z]{2,120}");
if (!nm.IsMatch(textBox2.Text))
{
  Message Box.Show("Enter Your Name Correctly ", "Error");
}


OR

Regex nm = new Regex(@"[a-z A-Z]{2,120}");
if (nm.Matches(textBox2.Text).Count == 0)
{
  Message Box.Show("Enter Your Name Correctly ", "Error");
}



Please vote and Accept Answer if it Helped.
 
Share this answer
 
Regex nm = new Regex(@"^[a-z A-Z]");

Now use this.
 
Share this answer
 
v2
Comments
Toli Cuturicu 28-Oct-10 8:09am    
Awful!
Lokesh Zende 29-Oct-10 5:37am    
Toli Cuturicu, that was some misatke.
Now chk this one.
Hiren solanki 29-Oct-10 6:42am    
'misatke' is still mistake.

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