RegEx to validate textarea and prevent spambots

I am getting spambots on my form and have done some form filtering but a big thing I am getting are URLs in my textarea form field. How would I code my form processing page using regular expressions to validate there are no URLs (i.e. - http://) in my textarea?

Example of what I need in bad code form:

commentsBox=request.form("comments")

regex = "{http://}"

if commentsBox contains regex then
WriteToFile "webcsv\myform_spam.csv", contents, True
else
WriteToFile "webcsv\myform.csv", contents, True
end if

Thanks!

~Aus2Srq
Aus2SrqAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThinkPaperIT ConsultantCommented:
you're just checking http:// URLs, nothing else?

you've got several variations to consider.. below's a good chunk of regex's to consider..

http://www.truerwords.net/articles/ut/urlactivation.html
0
ThinkPaperIT ConsultantCommented:
also.. what type of form is this? is it like a registration form?

considering using tools like CAPTCHA images to eliminate spam registration..
0
ddrudikCommented:

<%
Set regEx = New RegExp
regEx.Global = False
sourcestring = "your source string"
regEx.Pattern = ".*https?//"
Set Matches = regEx.Execute(sourcestring)
If Matches.Count > 0 then
 ' do something
Else
 ' do something else
End If
%>

Open in new window

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

ddrudikCommented:
One more change:
<%
Set regEx = New RegExp
regEx.Global = False
regEx.IgnoreCase = True
sourcestring = "your source string"
regEx.Pattern = ".*https?//"
Set Matches = regEx.Execute(sourcestring)
If Matches.Count > 0 then
 ' do something
Else
 ' do something else
End If
%>

Open in new window

0
Aus2SrqAuthor Commented:
Using your code as a base, I did a Google search and modified the code a bit as I don't care if I know the number of patterns found, I just need to know true or false I did the following.

However, it's failing to find the pattern and still submitting the form as normal. Do I need to change my variable to a string to search?

Thanks!

~A2S
commentsBox = request.form("comments")
 
Set regEx = New RegExp
With regEx
.Pattern = ".*https?//"
.IgnoreCase = True
.Global = False
End With
foundPattern = regEx.Test(commentsBox)
 
If foundPattern Then
  WriteToFile "webcsv\myform_spam.csv", contents, True
else
  WriteToFile "webcsv\myform.csv", contents, True
End If
Set regEx = nothing

Open in new window

0
ddrudikCommented:
I forgot the colon in the pattern, either revision would work with the new pattern below.  Note that you cannot test as you did, once the FoundPattern is created as a regEx.Test object it exists.  The best you can do is test if Matches.Count exists which reports false if it is equal to 0.
<%
Set regEx = New RegExp
regEx.Global = False
regEx.IgnoreCase = True
sourcestring = "http://www.yahoo.com/"
regEx.Pattern = ".*https?://"
Set Matches = regEx.Execute(sourcestring)
If Matches.Count then
  Response.Write "SPAM"
Else
  Response.Write "NOT SPAM"
End If
%>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Aus2SrqAuthor Commented:
Thank you very much ddrudik! It works perfectly.

On a side note, could you leave a last comment on how I would add an or in the regex? Such as looking for "http://" or "www.*.com" for instance.

Thanks again!

~Aus2Srq
0
ddrudikCommented:
Thanks for the question and the points.
<%
Set regEx = New RegExp
regEx.Global = False
regEx.IgnoreCase = True
sourcestring = "test www.yahoo.com test"
regEx.Pattern = "(?:.*https?://)|(?:.*www\..*\.com)"
Set Matches = regEx.Execute(sourcestring)
If Matches.Count then
  Response.Write "SPAM"
Else
  Response.Write "NOT SPAM"
End If
%>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.