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!

Using LEN Function

Status
Not open for further replies.

n0795

Programmer
Jul 30, 2001
136
US
I want to make user enter at least a certain number of characters in a search box

strString = Request.Form ("Name of input box on form")

If LEN(strString)< 3 THEN
Response.Write &quot;You need to enter at least 3 Characters&quot;

ELSE
'Continue on with code
'Continue on with results from database

I have tried this and it doesnt seem to work
 
Make sure you trim(strString), and cstr it too. just to be safe... see if that works.

eg: strString = trim(cstr(Request.form(&quot;box&quot;)))

leo leo
 
Another question. Is the data in the Database being stored as lower case data? Or all mixed?

-d
 
I have entered this before any other code on the page that displys my results
my form page is lets say /search.asp
and it posts to results.asp, which is where this code is
the field it looks in contains numbers and text

strString = trim(cstr(Request.form(&quot;Name&quot;)))


If LEN(strString)< 3 THEN
Response.Write &quot;You need to enter at least 3 Characters&quot;
ELSE

END IF

And it still isnt working I dont get any errors it just lets me search without entering any data or by entering one letter or number
Im stuck HELP HELP
 
Ok here is all my code for my results page with the LEN string added,Its a bit long but hopefully you might see something i dont..........
<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<%
strString = trim(cstr(Request.form(&quot;Name&quot;)))


If LEN(strString)< 3 THEN
Response.Write &quot;You need to enter at least 3 Character&quot;
ELSE

END IF


Dim SqlJunk


Set dbGlobalWeb = Server.CreateObject(&quot;ADODB.Connection&quot;)
dbGlobalWeb.Open(&quot;links&quot;)

SqlJunk = &quot;SELECT * FROM links&quot;



If Request.Form(&quot;TypeSearch&quot;) = &quot;Name&quot; Then
SqlJunk = SqlJunk & &quot; WHERE Name LIKE '%&quot; & Request.Form(&quot;Name&quot;) & &quot;%'&quot;
End If
Set rsGlobalWeb = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rsGlobalWeb.Open SqlJunk, dbGlobalWeb, 3
%>
<%
If rsGlobalWeb.BOF and rsGlobalWeb.EOF Then%>
<h2 align=&quot;center&quot;><font color=&quot;#FFFFFF&quot;>We did not find a Match</font></h2>
<%Else%>
<%If Not rsGlobalWeb.BOF Then%>
<h2><font color=&quot;#FFFFFF&quot;>Here are the Results of your search</font>

<table BORDER=&quot;1&quot; width=&quot;100%&quot; cellpadding=&quot;3&quot; bgcolor=&quot;#0000CC&quot;>
<tr>
<th bgcolor=&quot;#0000FF&quot; width=&quot;6%&quot;><font face=&quot;Arial&quot; color=&quot;#FFFFFF&quot;>Name
</font></th>
<th bgcolor=&quot;#0000FF&quot; width=&quot;9%&quot;><font face=&quot;Arial&quot; color=&quot;#FFFFFF&quot;>Address</font></th>
<th bgcolor=&quot;#0000FF&quot; width=&quot;6%&quot;><font face=&quot;Arial&quot; color=&quot;#FFFFFF&quot;>Submitted</font></th>
<th bgcolor=&quot;#0000FF&quot; width=&quot;12%&quot;>
<p><font face=&quot;Arial&quot; color=&quot;#FFFFFF&quot;>Added By</font><font face=&quot;Arial&quot; color=&quot;#FFFFFF&quot;>
</font></p>
</th>
<th bgcolor=&quot;#0000FF&quot; width=&quot;6%&quot;><font face=&quot;Arial&quot; color=&quot;#FFFFFF&quot;>EMail</font></th>
</tr>
<%
Do While Not rsGlobalWeb.EOF
%>
<tr bgcolor=&quot;#CCCCCC&quot;>
<td width=&quot;6%&quot;><font color=&quot;#000000&quot;><%=rsGlobalWeb(&quot;Name&quot;)%></font></td>
<td><font color=&quot;#000000&quot;><%=rsGlobalWeb(&quot;Address&quot;)%></font></td>
<td width=&quot;6%&quot;><%=rsGlobalWeb(&quot;submitted&quot;)%></td>
<td width=&quot;12%&quot;><%=rsGlobalWeb(&quot;adder&quot;)%></td>
<td width=&quot;6%&quot;><%=rsGlobalWeb(&quot;email&quot;)%></td>
</tr>
<% rsGlobalWeb.MoveNext
Loop
%>
</table>
<%End If%>
<%End If%>
<%
rsGlobalWeb.Close
dbGlobalWeb.Close
%>
 
Do you want to stop the search page from submitting if the users search criteria is less than 3 characters? If so, you'll have to use client side javascript/vbscript and have it fire on the forms onSubmit event ...

<script language=&quot;javascript&quot;>
<!---
function checklength(theForm)
{
var strCriteria = theForm.Criteria.value;

if (strCirteria.length < 3)
{
alert('you have to enter at least 3 characters.');
return false;
}

return true;
}
//-->
</script>
<form onSubmit='return checklength(this);'>
<input type=&quot;text&quot; name=&quot;criteria&quot;>
<input type=&quot;submit&quot;><input type=&quot;reset&quot;>
</form>
 
thanks for your help I think Im close
Where you say (theform) what name do i use there eg:serach.asp or just search
<script language=&quot;javascript&quot;>
<!---
function checklength(theForm)
{
var strCriteria = theForm.Name.value;

if (strCirteria.length < 3)
{
alert('you have to enter at least 3 characters.');
return false;
}

return true;
}
//-->
</script>



<form action=&quot;Results.asp&quot; method=&quot;post&quot; onsubmit='return CheckLength(this);'>
<input type=&quot;text&quot; size=&quot;30&quot; name=&quot;Name&quot;>
<input type=&quot;submit&quot;
name=&quot;B1&quot; value=&quot;Search&quot;>
<input type=&quot;reset&quot; name=&quot;B2&quot; value=&quot;Clear&quot;>

Does this look right
 
I got it thanks for all your help
I have been looking at too much code today
Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top