这里所有的答案,或者允许与其他方案的网址(例如file://,ftp://)或拒绝人类可读的网址不启动http://或https://(例如www.google.com)与用户输入打交道时,这是不好的。
这是我的方法:
public static bool ValidHttpURL(string s, out Uri resultURI)
{
    if (!Regex.IsMatch(s, @"^https?:\/\/", RegexOptions.IgnoreCase))
        s = "http://" + s;
    if (Uri.TryCreate(s, UriKind.Absolute, out resultURI))
        return (resultURI.Scheme == Uri.UriSchemeHttp || 
                resultURI.Scheme == Uri.UriSchemeHttps);
    return false;
}
用法:
string[] inputs = new[] {
                          "https://www.google.com",
                          "http://www.google.com",
                          "www.google.com",
                          "google.com",
                          "javascript:alert('Hack me!')"
                        };
foreach (string s in inputs)
{
    Uri uriResult;
    bool result = ValidHttpURL(s, out uriResult);
    Console.WriteLine(result + "\t" + uriResult?.AbsoluteUri);
}
输出:
True    https://www.google.com/
True    http://www.google.com/
True    http://www.google.com/
True    http://google.com/
False