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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instr string

Status
Not open for further replies.

n0795

Programmer
Jul 30, 2001
136
US
Basicly I have Textarea named "discription" and I would like to check this field and ALL the words in it for any bad words listed in my string 'below'
<%
Form_discription = Request.Form(&quot;discription&quot;)

Validated_Form = true

IF InStr(Form_discription,&quot;badword&quot;,&quot;badword2)=1 THEN ....&quot;here i would like to put more words&quot;.......
Validated_Form = false
END IF

IF NOT Validated_Form THEN
%>
<HTML>
<BODY>
We said no cussing . Click back in your browser, and fill it out properly!
</BODY>
</HTML>

<%
ELSE
'Here you can insert the info to a database, or send it
'with JMail to you mail account. If you send it to a db, make sure
'to remove any possible ' chars.%>
What do I need to change to do this.?
What am I doing wrong Im kinda new to ASP
Any help would be great....
This will work with one word in the string but it doesnt work with two like shown,It only checks for one word and i want it to check the whole textarea.
 
I assume this is VB script?

The inStr function will only accept one argument for comparing. The following code worked just fine
Code:
Private Sub CheckStr()
Dim mystr
mystr = &quot;Some bad words go here&quot;
If InStr(mystr, &quot;go&quot;) Then
MsgBox &quot;Word found&quot;
Else
MsgBox &quot;Word not found&quot;
End If
End Sub

Here's the syntax from the Microsoft web site

InStr([start, ]string1, string2[, compare])

Arguments
start

Optional. Numeric expression that sets the starting position for each search. If omitted, search begins at the first character position. If start contains Null, an error occurs. The start argument is required if compare is specified.

string1

Required. String expression being searched.

string2

Required. String expression searched for.

compare

Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values. If omitted, a binary comparison is performed.

 
Really I was looking for a way to do this in ASP
 
VBScript is one of the languages used in ASPs. The inStr function is VBScript, which is a subset of Visual Basic. The internet server intrepets the script and returns the results to the browser.

The problem your are encountering is that you're using the incorrect number of arguments. inStr only accepts one argument for comparison. You'll probably have to use a for next loop and an array that contains your bad words.

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top