Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to prevent visitors from inputting very long words in my forum? 1

Status
Not open for further replies.

Andel

Programmer
Joined
Feb 15, 2001
Messages
366
Location
US
Some visitors are making fun of my forum, like entering any kind letters like "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx". I'd like asp to detect these long words in my forum and prevent it from being posted. Thanks in advance.

Andel
andel@barroga.net
 
two ways

use client side js to check the word length on submitting the form. (easy to get around)

use serverside asp to do a simple check on length

Code:
if len(strText)>20 then
  response.write "string to long"
else
  response.write "string ok"
end if

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
You could always start a table in your database for prohibited words. Then each time someone posts you can do an instr or find or some method like that to detect if it contains something prohibited. Code looks something like:

Code:
<%
dim cn, rs
dim iCheck, iCount

set cn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")

with cn
    .Provider = "Your Provider"
    .Connectionstring= "Connection String"
    .open
end with 

rs.open "Select * from words",cn,3,3

do until rs.eof = true 
iCheck = instr(1,Request.Form("PostText"),rs("Word"),1)

if iCheck > 1 then
'I put a counter here but you could have 
'something here to deal with deleting the word or 
'replacing it with something.

   iCount = iCount + 1
end if
rs.movenext
loop

Response.write "There were " & iCount & "restricted words."

%>


Problem with this is you still have to make sure and keep up your restricted words. Then if they modify them by one letter or then you have to add those as well. You can also try code to find massive number of repeated characters or maybe use some client side logic to make sure no character is repeated more than five times.

Here is some code for that:

Code:
<html>
<title></title>
<head>
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub txtPost_onkeyup
dim sText1,sText2, iCount, iLen, i

iLen = len(txtPost.value )

for i = 1 to iLen
	sText1 = mid(txtPost.value,i,1)
	if sText1 = sText2 then
		iCount = iCount + 1
	end if
	sText2 = sText1
	
	if iCount = 5 then
		msgbox "Please do not repeat one character more than 5 times."
		txtPost.value = left(txtPost.value , iLen - 1)
		exit sub
	end if
	
next

End Sub

-->
</SCRIPT>
</head>
<body>
<input type="text" name="txtPost" id="txtPost">
</body>
</html>
You will also have to be aware of case so you might think about just making everything lower case using lcase function so people can't use TeSt to get away with something.

Anyway I can think of would require you to maintain a table and use a check.

Let me know if you need more examples of these methods or maybe have a better idea.

Cassidy
 
You could just truncate them. It would seem that anything over x characters -- pick a number -- is clearly a problem, but rather than dumping it you could put ellipses in the middle or something, dunno. Like this:
Code:
Dim strMyText, intMaxLength, aryWords, i

strMyText = Request.Form("TextValue")

intMaxLength = 30 [COLOR=gray]'Change to suit[/color]

aryWords= Split(strMyText, " ")

For i = 0 to UBound(aryWords)
  If Len(aryWords(i) > intMaxLength Then
    aryWords(i) = Left(aryWords(i), 3) & "..." & Right(aryWords(i), 3)
  End If
Next

strMyText = Join(aryWords, " ")
Now strMyText contains your text, with any words longer than 30 characters being converted to their first three letters, three dots, and their last three letters. Such that xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx becomes xxx...xxx
 
Regular expressions are your friends :)
Code:
Const WORDY_PATTERN = "([^\s]{40})(([^\s]{10,})+)"

Function IsWordy(aStr)
	Dim regex
	Set regex = New RegExp
	regex.Pattern = WORDY_PATTERN

	IsWordy = regex.Test(aStr)
End Function

Function DeExtremeWordify(aStr)
	Dim regex
	Set regex = New RegExp
	regex.Pattern = WORDY_PATTERN

	DeExtremeWordify = regex.Replace(aStr,"$1- $2")

	Set regex = Nothing
End Function

Then you would just do something like:
Code:
Do While IsWordy(MyString)
   MyString = DeExtremeWordify(MyString)
Loop

It could obviously be made a little more efficient and you may want to change the limits I set in the expression or alter it to ignore tags, but beat checking the length of every word in your document.

-T

barcode_1.gif
 
Hey, no using regular expressions to improve speed and efficiency! :-P
 
I agree that was definatly cheating. I know I need to remember to use them. Just always seem to look at brute force and well you know the other half before I look at the better way. I think that deserves a star there.
 
Tarwn:
why ([^\s]{40})(([^\s]{10,})+) pattern???

is it for the DeExtremeWordify thingy???

Known is handfull, Unknown is worldfull
 
I was using that pattern for the regex in both the IsWordy check and the DeExtremeWordify thingie :) The numbers can be changed, I was just playing around with differant size fields and those were the last numbers I messed with - trying to get looped submatches so it could be done in one call, but it didn't work :(

-T

barcode_1.gif
 
Should tell it to accept minimum 10 repeats, no maximum...or am I smoking from the wrong pipe again? :P

barcode_1.gif
 
yup tarwn is right, the empty comma doesnt set a maximum limit...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top