Is there a Vbscript function for finding special characters?

Posted on 2007-10-11
Last Modified: 2008-01-09
I need a function that will extract all special characters from a string.  Is there a function that can accomplish this, something like isNumeric?  Basically I want to insure that a string a user enters doesnt contain any special characters, or if it does, extract them all so only numeric, or alpha characters remain?
Question by:tentavarious
    LVL 9

    Accepted Solution

    Dim regEx
    Set regEx = New RegExp
    regEx.Global = True
    regEx.Pattern = "\W"
    varName = regEx.Replace(incomingVar,"")

    Regular Expressions
    LVL 9

    Expert Comment

    The pattern I show '\W' means 'Match anything NOT alphanumeric'

    The opposite is '\w' which means 'Match anything that IS alphanumeric'

    The NOT means that the regEx.Replace replaces 'anything NOT alphanumeric' with a 'nothing'
    LVL 9

    Expert Comment

    Quick additional note \W and \w consider the underscore '_' to be allowed in the 'alphanumeric' set. If you want ONLY letters and numbers to pass through and nothing else, change the pattern to

    regEx.Pattern = "[^A-Za-z0-9]"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (…
    I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    794 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

    16 Experts available now in Live!

    Get 1:1 Help Now