Solved

Function in Classic ASP to Remove Invalid Characters

Posted on 2008-10-07
4
4,006 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDF Embed pdfobject.js local path problem regular ASP 2 181
Pass through dll 2 92
Time Conversions...both ways 2 17
Html CheckBox obtain Its Value 5 28
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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