Solved

Function in Classic ASP to Remove Invalid Characters

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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 …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now