Print Page | Close Window

Validate a URL

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1338
Printed Date: 28 March 2026 at 11:07pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Validate a URL
Posted By: gknapper
Subject: Validate a URL
Date Posted: 25 March 2003 at 2:56pm

I need to have a URL validated before a form can be submitted.  I need it to look at a text field and add what the user has placed in the field allown with a hidden field.

hiddenfield+field1

If the result is true that the url is there then have it continue and send the form otherwise error with a message.

Thanks,

Greg




Replies:
Posted By: michael
Date Posted: 25 March 2003 at 3:53pm

Use XML like below. This is a function I found some time ago and does work good. It was actually a vb function but I think it should work now for vbscript......

<%
Function val_url(UrlName)
Dim objHTTP, sHTML
On Error Resume Next
val_url = false
if UrlName <> "" Then
if left(lcase(UrlName),7)<>"http://" Then
UrlName="http://" & UrlName
End if
Set objHTTP = Server.CreateObject ("Microsoft.XMLHTTP")
objHTTP.open "HEAD", UrlName, False
objHTTP.send
sHTML=objHTTP.statusText
if err or sHTML<>"OK" Then
val_url=false
else
val_url=true
End if
Set objHTTP=nothing
End if
End Function

Dim vStrUrl

vStrUrl=request.form("hiddenfield") & request.form("textfield")
if vStrUrl <> "" then
if val_url(vStrUrl) then
Response.write"<br><br>A Valid URL"     'submit your form here
else
Response.write"<br><br>NOT a Valid URL" 'spit out whatever error you have
end if
end if
%>




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net