Solved

Function in Classic ASP to Remove Invalid Characters

Posted on 2008-10-07
4
3,972 Views
Last Modified: 2012-05-05
HI there I have a questionaire which is comprised of 5 text fields and 1 texarea form field. I would like a function to strip out all invalid characters from each of these strings before I submit them to my stored procedure. Does anyone have a fuction that does this?
0
Comment
Question by:MayoorPatel
  • 2
4 Comments
 
LVL 7

Assisted Solution

by:bluV11t
bluV11t earned 50 total points
ID: 22657821
Hi!
This removes semicolons, apostrophe and chars that comment out lines and blocks in your sql and hinders the execution of buildt in procedures starting with xp_. Be ware line 9 would also mess up dates depending on your date format.
<%
function dbsafe(data)
data = replace(data,";","")
data = replace(data,"'","")
data = replace(data,"--","")
data = replace(data,"/*","")
data = replace(data,"*/","")
data = replace(data,"*","")
data = replace(data,"/","")
data = replace(data,"xp_","")
end function
%>

Open in new window

0
 
LVL 1

Author Comment

by:MayoorPatel
ID: 22657984
Ok I've managed to find this function

Dim regExp
Set regExp = new regexp
regExp.Pattern = "[^A-Z^a-z^0-9\s]"   'any character that is not 0 to 9
regExp.Global = True             'search the entire string

Can someone who knows about reg expressions tell me if this takes care of all invalid characters?
0
 
LVL 12

Accepted Solution

by:
R_Harrison earned 450 total points
ID: 22659210
Yes, it strips out all non numeric or alpha characters, in other words only 12345676890 and letter A-Z are allowed.

You can put this in a function to makesafe your strings as below...
Function makesafe(strInput)
	Dim objRegExp, strOutput
	Set objRegExp = New Regexp
	objRegExp.IgnoreCase = True
	objRegExp.Global = True
	objRegExp.Pattern = "[^A-Z^a-z^0-9\s]"
	makesafe = objRegExp.Replace(strInput, "")
End Function

Open in new window

0
 
LVL 1

Author Closing Comment

by:MayoorPatel
ID: 31503756
Ta very much!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Web Traffic Limitations 4 61
SQL Filter Question 8 83
How to show result of a NULL value at random? 32 50
jquery to restrict certain words from input in form 11 34
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

770 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