Solved

Function in Classic ASP to Remove Invalid Characters

Posted on 2008-10-07
4
4,130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 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