Is there a Vbscript function for finding special characters?

Posted on 2007-10-11
Medium Priority
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
  • 3

Accepted Solution

CCongdon earned 500 total points
ID: 20058238
Dim regEx
Set regEx = New RegExp
regEx.Global = True
regEx.Pattern = "\W"
varName = regEx.Replace(incomingVar,"")

Regular Expressions

Expert Comment

ID: 20058259
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'

Expert Comment

ID: 20058286
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]"

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

839 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