4 Answers
4

It depends on the context in which you're asking for a URL. If the url is supposed to be a fully qualified URL (http://example.com/foo/bar/baz) you can safely assume http:// if they haven't prefixed it with http, https, file, ftp, and any other possible acceptable protocols.

If, instead, you're asking for a url that may or may not be relative to the current domain, you wont be able to assume any protocol, although you could provide a default value of http:// as starter text

For a great example of where this is used, look no further than Stack Exchange's own link field in the popup used in the question/answer content editor (Ctrl + L).

+1, but I would not restrict the acceptable protocols to the few that are very well known. At work we use a custom URI protocol to exchange links to specific information within our software. Typing that in a browser or in the "Run" box on the start menu will start our software and execute a query that corresponds to the info in the URI. Custom URI protocols need to be registered, so you should be able to enumerate the known protocols...
–
Marjan VenemaMay 6 '12 at 8:25

@MarjanVenema, again, "It depends on the context in which you're asking for a URL". If you're asking a user for the link to their website (URL field in comments), you wouldn't accept anything other than http or https, so it truly depends on what protocols are accepted in the circumstances. If any protocol is acceptable, then you'd need to check if the user has provided a protocol.
–
zzzzBovMay 6 '12 at 16:35

1

Yes, I wasn't arguing against that. I just tried to address that "if they haven't prefixed it with..." might just lead people to check for a specific and limited set of starter strings, instead of checking for all registered protocols, or, even better parsing the URI and checking for no or any protocol.
–
Marjan VenemaMay 6 '12 at 17:39