IsValidUrl

Returns true when a string is a valid url

源代码:

1
2
3
4
5
6
7
public static class MyExtensionMethods {
public static bool IsValidUrl(this string text) {
Regex rx = new Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
return rx.IsMatch(text);
}
}
}

示例:

1
2
3
test
test
test
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×