Regular Expression to remove "/", "\", "" and "="


Can anyone please show me the regular expression to reject a string ("<blue>" etc.) which has the following expression in it:
"/", "\", "" and "="</blue>
0
rajabadsha
7/31/2008 11:59:51 AM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 4 followers.

💬 7 Replies
👁️‍🗨️ 2018 Views



 hi, It may Help u..
it is in Class file u may use this expressin in validation controls also.
Regex objReg = new Regex(@"^[^,.?/\~|`;:']*$", RegexOptions.Singleline);
Regex objReg = new Regex(@"^[^,][^.][^?][^/][^\][^~|][^`][^;][^:][^'][[^]$", RegexOptions.IgnoreCase);

Thanks & Regards,
Murthy.
0
murthysrn
7/31/2008 12:28:57 PM

Tried it but it did not work. Also the @ sign at the begining generates error
0
rajabadsha
7/31/2008 12:44:36 PM

 
if (objReg.IsMatch(txtboxName))
{
pstrMessage = "TRUE";
}
else

txtboxName= "Enter Valid " + pstrTxtBoxName + ".";
}
objReg = null;

Thanks & Regards,
Murthy.
0
murthysrn
7/31/2008 1:22:22 PM

The @ sign is the way you escape strings in C#, you do not have to do that in VB.
I suggest www.regexlib.com and Roy Osherov's Regulazy as great places to get started with regular expressions in .net. Roy is having an issue with his hosting provider at the moment. http://weblogs.asp.net/rosherove/
I am going to check with him about what his status is.

Chris Love
ASP.NET 2.0 Your Visual Blueprint for developing Web Applications
0
docluv
7/31/2008 1:33:08 PM

Just an additional note; it is much better to construct the regex to allow acceptable characters than it is to remove specific characters.  I also second the suggestion to check the site mentioned by a previous response.  I found it to be very high quality.
0
kraznodar
7/31/2008 1:51:38 PM

kraznodar:
it is much better to construct the regex to allow acceptable characters than it is to remove specific characters.
 
 
He wants to remove 5 characters;
Are you suggesting he writes one to "allow" each of the other 251 or 65531 characters of his character set?


            

originalPoster = forumthread.GetOP;
answerPost = originalPoster.Answerfound(forumthread);
(answerPost!=null?answerPost.markAsAnswer():originalPoster.GiveMoreInfo(forumthread));
0
Emyr
7/31/2008 4:37:13 PM

Emyr:

kraznodar:
it is much better to construct the regex to allow acceptable characters than it is to remove specific characters.
 

 

He wants to remove 5 characters;

Are you suggesting he writes one to "allow" each of the other 251 or 65531 characters of his character set?


Yes, it takes typing about 12 characters as compared to typing the 6 to 7 characters to remove that list of 5 and is recommended by every security pro even vaguely familiar with RegEx.  To put it in other terms; If you have a secure facility and only the 20 people who work there are allowed in you get better sercurity than if you let everyone except the 5 known security risks in.  If the pool of people is 65531 it is better to allow only 20 rather than 65511 while hoping that there were only 5 threats and not 6 or more.
Regex is like SQL, C#, VB, HTML, javascript, CSS or any other script or language.  When well written it is affective and beautiful and ugly when not.
0
kraznodar
7/31/2008 7:20:39 PM
Reply: