Hi,

I would like to know is there a generic rule that I can follow to determine
if the string is a valid URL?
eg. prefix is http, www...etc.

Re: Web expression by McKirahan

McKirahan
Mon Aug 14 08:12:09 CDT 2006

"Alan T" <alanpltseNOSPAM@yahoo.com.au> wrote in message
news:uGU2Cy2vGHA.3912@TK2MSFTNGP03.phx.gbl...
> Hi,
>
> I would like to know is there a generic rule that I can follow to
determine
> if the string is a valid URL?
> eg. prefix is http, www...etc.

By valid do you mean does it exist or do you mean well formed?

RFC 1738 will help you determine if a URL is well formed;
http://www.faqs.org/rfcs/rfc1738.html

To test if a URL exists you could use XMLHTTP:

Option Explicit
Const cVBS = "ExistURL.vbs"
Dim strURL
strURL = InputBox("Enter a URL",cVBS)
WScript.Echo strURL & " = " & Fetch(strURL)

Function Fetch(URL)
On Error Resume Next
Err.Clear
Dim objXML
Set objXML = CreateObject("Microsoft.XMLHTTP")
objXML.Open "GET",URL,False
objXML.Send
If Err.Number <> 0 Or objXML.Status <> 200 Then
Fetch = False
Exit Function
End If
Set objXML = Nothing
Fetch = Err.Number = 0
End Function




Re: Web expression by Alan

Alan
Mon Aug 14 19:04:10 CDT 2006

Hi,

I just want to check the string is a valid format.
I don't need a too detail check but a more general one.
Besides these prefixes:
http://
www.
https://

And suffixes:
.htm
.html

What other I need to check?


"McKirahan" <News@McKirahan.com> wrote in message
news:Ga6dnbmZY_g0633ZnZ2dnUVZ_q6dnZ2d@comcast.com...
> "Alan T" <alanpltseNOSPAM@yahoo.com.au> wrote in message
> news:uGU2Cy2vGHA.3912@TK2MSFTNGP03.phx.gbl...
>> Hi,
>>
>> I would like to know is there a generic rule that I can follow to
> determine
>> if the string is a valid URL?
>> eg. prefix is http, www...etc.
>
> By valid do you mean does it exist or do you mean well formed?
>
> RFC 1738 will help you determine if a URL is well formed;
> http://www.faqs.org/rfcs/rfc1738.html
>
> To test if a URL exists you could use XMLHTTP:
>
> Option Explicit
> Const cVBS = "ExistURL.vbs"
> Dim strURL
> strURL = InputBox("Enter a URL",cVBS)
> WScript.Echo strURL & " = " & Fetch(strURL)
>
> Function Fetch(URL)
> On Error Resume Next
> Err.Clear
> Dim objXML
> Set objXML = CreateObject("Microsoft.XMLHTTP")
> objXML.Open "GET",URL,False
> objXML.Send
> If Err.Number <> 0 Or objXML.Status <> 200 Then
> Fetch = False
> Exit Function
> End If
> Set objXML = Nothing
> Fetch = Err.Number = 0
> End Function
>
>
>



Re: Web expression by McKirahan

McKirahan
Mon Aug 14 21:12:08 CDT 2006

"Alan T" <alanpltseNOSPAM@yahoo.com.au> wrote in message
news:usNQW5$vGHA.4444@TK2MSFTNGP05.phx.gbl...
> Hi,
>
> I just want to check the string is a valid format.
> I don't need a too detail check but a more general one.
> Besides these prefixes:
> http://
> www.
> https://
>
> And suffixes:
> .htm
> .html
>
> What other I need to check?

[snip}

> > RFC 1738 will help you determine if a URL is well formed;
> > http://www.faqs.org/rfcs/rfc1738.html

Study the above. Here are some highlights:

Scheme names consist of a sequence of characters. The lower case
letters "a"--"z", digits, and the characters plus ("+"), period
("."), and hyphen ("-") are allowed. For resiliency, programs
interpreting URLs should treat upper case letters as equivalent to
lower case in scheme names (e.g., allow "HTTP" as well as "http").

Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL.