Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am new to regular expression.I am working on C# win form application.I need to validate one textbox using regular expression which should allow a-z,A-Z,0-9 and special characters like hypen(-),underscore(_),slash(/) and white space.
Please help me to write the Regx expression for the above requirement.
Posted

here is the ReGex i use for password fields... all the letters and symbols are allowed, and range is from 0 to maximum... * represents= 0 or more than 0 can exists

^[a-zA-Z0-9]*[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]*$

but this will not allow a letter once a symbol is entered...
so you can modify it to

^[a-zA-Z0-9,!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]*$
 
Share this answer
 
Comments
BillWoodruff 15-Jan-12 4:52am    
Looks like a solid answer, and I voted it a #5 :)

But, I am curious to ask you ... about using your first RegEx: which you state: "will not allow a letter once a symbol is entered:" does that mean that once you have entered a symbol, then only other symbols can be entered ?

I'd be curious to know why you wrote the first example the way you did.

thanks, Bill
psychic6000 15-Jan-12 4:59am    
yes, like
my1name23_!
so there is another thing
^[a-zA-Z0-9,!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]{6,32}$
now this will not allow less than 6 and more than 32 as length
BillWoodruff 15-Jan-12 12:26pm    
Very cool, thanks ! best, Bill
Andreas Gieriet 15-Jan-12 8:51am    
Why all these commas? Once is enough. The comma does not separate elements in regex, correct?
psychic6000 15-Jan-12 11:54am    
thanks for telling... i didnt know that :)

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