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

check text before creating a hyperlink

Status
Not open for further replies.

jordan11

Technical User
May 24, 2003
150
0
0
GB
Hi,

I have this piece of code that allows a user to enter there web address or email address. Can some please tell me how I can prevent text such as N/A being a hyper link if the user enters it in the text box. I just want valid address to be hyperlink ie http and www.

This is my code
<td >
<% If strWeb <> "" Then %>
<a href=" rel="external" title="View Company Website (opens in a new window)"><%=strWeb%></a>&#160;
<% end if %>
</td>

Thanks In advance

JJ
 
You can test the strWeb using regexp. A rough version scripted off-hand is this. The central piece of it is the construction of a proper pattern. It is a game for sophistication so much out there that you can search for a full-fledged pattern. But you can use a much reduced and more manageable custom construction to suit your particular need and your knowledge on your own data pattern to be managed.
[tt]
<%
set re=new regexp
with re
.ignorecase=false
.pattern="^end with
%>
<td >
<% If [blue]re.test(strWeb)[/blue] Then %>
<a href=" rel="external" title="View Company Website (opens in a new window)"><%=strWeb%></a>&#160;
<% end if %>
</td>
[/tt]
Be sure to build up adding sophistication to the pattern (or search the net for one). I reiterate the one shown is off-hand with limited range of applicability.
 
Thanks for your reply,
will the above code allow me to still display the text that they entered even if it is not a web or email address, as that is what I need.

JJ
 
If you still want to display as such when the testing fails, it is this.
[tt]
<% If re.test(strWeb) Then %>
<a href=" rel="external" title="View Company Website (opens in a new window)"><%=strWeb%></a>&#160;
[blue]<% else %>
<pre><%=strWeb&></pre>[/blue]
<% end if %>
[/tt]
I use pre-tag for safety in case strWeb contains some characters that may cause trouble in displaying. Feel free to relax that.
 
Thanks for your help,

I used the code below but it does not display a hyperlink it just shows a plain text format even when there should be a hyper link not sure waht is wrong

<%
set re=new regexp
with re
.ignorecase=false
.pattern="^end with
%>
<tr>
<td class="size10" colspan="2">
<% If re.test(sWebAddr) Then %>
<a href=" rel="external" title="View Company Website (opens in a new window)"><%=sWebAddr%></a>&#160;
<%else
response.Write(sWebAddr)
end if %>

</td>
</tr>
 
It probably is because you have some bit in the valid string that you are not disclosing at all. The pattern's limited applicability I have said more than once!

It validate for instance
[tt] s=" s="[/tt]
but not, for instance,
[tt] s="[/tt]
because of the use of \w. Try for instance expand it a bit.
[tt]
.pattern
="^[0-9a-zA-Z_-]+\.(com|org|gov)/{0,1}$"
[/tt]
will validate "tek-tips.com".

You get the idea. Look at expanding the \w part and other possible structure of a valid url. I cannot guarantee universality. You have to search the net for a full-fledged one, as I said before.
 
sorry for some reason I am getting a type mis match with test
 
Type mismatch?! Try look what do you get with strWeb.
[tt] response.write typename(strWeb) & "<br />" & vartype(strWeb)[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top