// Fetch the HTML Title from remote page public void GetTitle() { // Check Prefix System.Globalization.CompareInfo cmpUrl = System.Globalization.CultureInfo.InvariantCulture.CompareInfo; if (cmpUrl.IsPrefix(this.tb_LinkUrl.Text, "http") == false) { this.tb_LinkUrl.Text = "http://" + this.tb_LinkUrl.Text; } }
public static bool IsValidUrl(string url) { if (string.IsNullOrEmpty(url)) { return(false); } System.Globalization.CompareInfo cmpUrl = System.Globalization.CultureInfo.InvariantCulture.CompareInfo; if (cmpUrl.IsPrefix(url, "http://") == false && cmpUrl.IsPrefix(url, "https://") == false) { url = "http://" + url; } //Regex urlRegex = new Regex("(^|[^\\w'\"]|\\G)(?<uri>(?:https?|ftp)://(?:[^./\\s'\"<)\\]]+\\.)+[^./\\s'\"<)\\]]+(?:/.*?)?)(\\.[\\s<'\"]|[\\s,<'\"]|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase); // Regex("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(/?([^#]*))?(#(.*))?"); //^((https?|ftp)://|(www|ftp)\.)[a-z0-9-]+(\.[a-z0-9-]+)+([/?].*)?$ Regex urlRegex = new Regex("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(/?([^#]*))?(#(.*))?"); return(urlRegex.IsMatch(url)); }
public static bool IsValidUrl(string url) { bool bResponse = false; System.Globalization.CompareInfo cmpUrl = System.Globalization.CultureInfo.InvariantCulture.CompareInfo; if (cmpUrl.IsPrefix(url, @"http://", System.Globalization.CompareOptions.IgnoreCase) == false) { url = @"http://" + url; } Regex RgxUrl = new Regex(@"^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$", RegexOptions.Compiled | RegexOptions.IgnoreCase); if (RgxUrl.IsMatch(url)) { bResponse = true; } else { bResponse = false; } return(bResponse); }