2014/07/29

How to check if url is valid in C# ?

public bool IsUrlValid(string url)
{
string pattern =
@"^(http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$";
Regex reg = new Regex(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
return reg.IsMatch(url);
}
view raw gistfile1.cs hosted with ❤ by GitHub

No comments:

Post a Comment