title: Check the Syntax of a URL via VBS Script
body: <p>Is there a way to check the syntax of a URL via visual basic? Here is my code below. I need a way to just check the syntax and to be sure it is correct (i.e has http, .com or .net or .edu). I need to check the format to be sure the url's are typical of standard url format. Can this be done?</p>
  
  <pre><code>Public PageSource As String
  Public httpRequest As Object
  
  Function GetURLStatus(ByVal URL As String, Optional AllowRedirects As Boolean)
  
      Const WinHttpRequestOption_EnableRedirects = 6
  
  
          If httpRequest Is Nothing Then
              On Error Resume Next
                  Set httpRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
                  If httpRequest Is Nothing Then
                      Set httpRequest = CreateObject("WinHttp.WinHttpRequest.5")
                  End If
              Err.Clear
              On Error GoTo 0
          End If
  
  
            httpRequest.Option(WinHttpRequestOption_EnableRedirects) = AllowRedirects
  
  
  
            If InStr(1, URL, "://") = 0 Then
               URL = "http://" &amp; URL
            End If
  
  
                 On Error Resume Next
                    httpRequest.Open "GET", URL, False
                    If Err.Number &lt;&gt; 0 Then
                     ' Handle connection errors
                       GetURLStatus = Err.Description
                       Err.Clear
                       Exit Function
                    End If
                 On Error GoTo 0
  
  
                 On Error Resume Next
                    httpRequest.Send
                    httpRequest.WaitForResponse
                    If Err.Number &lt;&gt; 0 Then
  
                       PageSource = "Error"
                       GetURLStatus = Err.Description
                       Err.Clear
                    Else
  
                       GetURLStatus = httpRequest.Status &amp; " - " &amp; httpRequest.StatusText
  
                       PageSource = httpRequest.ResponseText
                    End If
                 On Error GoTo 0
  
  End Function
  </code></pre>