Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I need regex in C#

My condition is minimum of 6 max of 30, and accepts special characters, numbers, and letters.

Please help me with this? Thanks
Posted
Updated 2-Feb-10 11:13am
Comments
lewax00 29-Nov-12 14:21pm    
Are you sure you really need a Regex for this? Why not just check the length of the string?

.{6,30}

Dot (.) matches any character except line breaks (\n), unless you specify RegexOptions.Singleline in the Regex constructor, in which case it matches every single character. And it always matches carriage return (\r), just in case you were wondering. And 6,30 is the range of characters to match using the match expression to the left of the range (in the above case, that would be dot). So, the above expression matches between 6 and 30 characters (of any type, except for \n depending on how you construct the Regex), inclusive.
 
Share this answer
 
I'm not going to give you the full solution, but I'll give you a close one, and you can finish it:
.{9,20}

I recommend you read up on regular expressions so you don't need to ask such basic questions.
 
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