Is there a Vbscript function for finding special characters?

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?
tentavariousAsked:
Who is Participating?
 
CCongdonConnect With a Mentor Commented:
<%
Dim regEx
Set regEx = New RegExp
regEx.Global = True
regEx.Pattern = "\W"
varName = regEx.Replace(incomingVar,"")
%>

Regular Expressions
0
 
CCongdonCommented:
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'
0
 
CCongdonCommented:
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]"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.