Click here to Skip to main content
15,881,044 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all

I have set of characters that has to be allowed in a string

Allowed charaters : ' { } [ ] \ ; ' : " , . / ? ! @ # $ % & * ( ) _ + - =

The characters that are not allowed are: ` ~ ^ | < >

can any body give me a regular expression for the above requirement.

I tried this

Regex.IsMatch(@"^[\~|\`|\^|\<|\>]*$")

but didn't work.

It is also validating for an empty string.
Posted

I haven't got Expresso loaded, (or VS - don't ask) so this is untested, but I suggest that you remove the leading '^', the trailing '$', and the repeat count '*'.
C#
Regex.IsMatch(@"[\~|\`|\^|\<|\>]")
May work better - at the moment you are looking for a string which consists entirely of zero or more repetitions of your illegal characters only.
 
Share this answer
 
 
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