Timeline for How to check whether a string is a valid HTTP URL?
Current License: CC BY-SA 4.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 10, 2020 at 10:23 | comment | added | Wouter Vanherck |
It's important to note that URL's like htt://google.com are accepted
|
|
| Mar 20, 2019 at 16:14 | comment | added | Epirocks | that's fine for me anyway I don't want to accept a url without http or https on it. So I use IsWellFormedUriString first, then use your function without regex. bool bResult = (Uri.IsWellFormedUriString(s, UriKind.Absolute) && ValidHttpURL(s, out uriResult)); Thanks | |
| Mar 19, 2019 at 11:05 | comment | added | 41686d6564 |
@Epirocks Exactly! The problem is that if you use IsWellFormedUriString before adding the http://, you'll end up rejecting things like google.com and if you use it after adding the http://, it'll still return true for http://mooooooooo. That's why I suggested checking if the string contains a . instead.
|
|
| Mar 19, 2019 at 11:02 | comment | added | Epirocks | moooooo by itself doesn't look like a url as it has no protocol on it. What I did was take out your regex match call, and &&'ed it with IsWellFormedUriString as well. | |
| Mar 19, 2019 at 9:40 | comment | added | 41686d6564 |
@Epirocks That's a good point. The problem is that http://mooooooooo is, in fact, a valid Uri. Therefore, you can't check for Uri.IsWellFormedUriString after inserting "http://" and if you check for it before, anything that doesn't have a Scheme will be rejected. Maybe what can be done is we check for s.Contains('.') instead.
|
|
| Mar 18, 2019 at 17:59 | comment | added | Epirocks | This lets through single words like "mooooooooo" but used in conjunction with Uri.IsWellFormedUriString could be good | |
| Oct 12, 2018 at 5:37 | history | answered | 41686d6564 | CC BY-SA 4.0 |