Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Function in Classic ASP to Remove Invalid Characters

Posted on 2008-10-07
4
Medium Priority
?
4,261 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 200 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 1800 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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 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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

704 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