How do you search a string for a series of special characters?

Posted on 2009-04-30
Last Modified: 2013-12-17
I have users entering data in a form, but I want to verify they didn't use special characters in their entries.  I'm new to C#, but am a programmer in other languages.  

I wanted to use Regular Expressions, but not sure how to implement it.  I'm not sure how to list the characters I was to exclude but include some of the standards like left and right single quotes, left and right double quotes, single and double quotes all together, en dash and em dash, forward and back slashes, at sign, pound sign and star.
Question by:samac1068
    LVL 20

    Expert Comment

    You could use the RegEx.IsMatch feature

    Author Comment

    That is helpful, but I still don't know how to write the Regular Expression string...since many of the characters I am searching for are special to RegEx.

    Author Comment

    This is what I am using as my string so far: \\\*\^\|[-#@/'"_]
    LVL 23

    Accepted Solution

    You can use the ^ to state not these characters. it might be easier to handle
    [^a-zA-Z0-9 \.]

    Open in new window


    Expert Comment

    personally, i hate writing regex expressions. that's why i use RegexBuddy

    It comes with a 7 day free trial:

    Author Comment

    I downloaded it is really good.  Helped me out a lot.  Thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now