Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to write one regular expression in C#. i have one strnig "Raj344ck". want to write one regular expression in C#. it should validate below conditions.

1.Length should be 8
2.First 2 char should be alphabetic.
3.Last 6 character should be alphanumeric.

Is it possible to achieve with single expression?

Thanks in advnace.
Posted

 
Share this answer
 
Comments
CPallini 14-Apr-15 5:53am    
5.
Kornfeld Eliyahu Peter 14-Apr-15 6:08am    
Thank you...
TheRealSteveJudge 15-Apr-15 2:16am    
Same idea. Even shorter. 5*
Try this:
C#
[a-zA-Z]{2}[a-zA-Z0-9]{6}
 
Share this answer
 
v3
Just to add to what Peter and TheRealSteveJudge say, if you want just 8 characters as teh whole string, you need to use string start and end delimiters as well:
^[a-zA-Z]{2}\w{6}$
If you don't, it's will also match
***HX123ABC%%%
 
Share this answer
 
Comments
aarif moh shaikh 14-Apr-15 6:27am    
5
TheRealSteveJudge 15-Apr-15 2:17am    
5*

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