You can use System.Uri.TryCreate
to check that; I’d use UriKind.Absolute
, though, because a lot of things are valid relative URIs.
Dim uri As Uri
If System.Uri.TryCreate(TextBox1.Text, UriKind.Absolute, uri) Then
' Navigate to it
Else
' Treat it as a search
End If
You could also make it a guess-free experience by requiring (or allowing) a prefix like ?
, which is easily checked with s.StartsWith("?")
and removed with s.Substring(1)
.
I just noticed the Ax
prefix; if you’re using an ActiveX control,
You can use
System.Uri.IsWellFormedUriString
with the same first two parameters to just do a check instead of also creating a URIDon’t