Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using like ....

C#
if (!Regex.Match(Name, @"^[a-zA-Z0-9]{2}$").Success)

Pls tel me correct way for this.
Posted
Updated 14-Nov-14 2:05am
v2
Comments
Kornfeld Eliyahu Peter 14-Nov-14 5:15am    
Remove the end of line sign ($)...
Kornfeld Eliyahu Peter 14-Nov-14 6:06am    
What characters? You defined a-z A-Z and 0-9...
http://www.regexper.com/#%5E%5Ba-zA-Z0-9%5D%7B2%7D%24
NarasinghRao 14-Nov-14 6:18am    
Sweet Answer Sir
Sergey Alexandrovich Kryukov 14-Nov-14 16:36pm    
You need to formulate exactly what you want. In a text, each and every its element is a "character". If you meant "letter", [a-zA-Z] only covers basic Latin letters, not all letters...
—SA

1 solution

You could just do: if (!Regex.Match(Name, @"^[0-z]{2}").Success)
 
Share this answer
 
Comments
NarasinghRao 25-Nov-14 6:37am    
how to minimize and maximize border-less win-form by clicking taskbar icon

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