14/09/2011 09:57, dhtml wrote:
> If you want to require the protocol to be explicit, the UI should
> indicate that in some way.
The protocol part is required in absolute URLs. But of course one might
consider prepending http:// if there is no protocol part.
> For example, use placeholder text that
> reads http://www.example.com, or use a label as "Address" or
> "Location" instead of "URL".
"URL" is much more accurate than "Address" or "Location" (which might
refer to postal addresses or geographic locations, for example). "Web
address" might do. Or "Web site address", if that's what one is asking for.
> Validate the "location" field with a regexp on the client and on the
> server.
That's non-trivial. Would you write one that accepts foo://example.com
and reject
http://www.sää.fi for example?
If the intent is to check that the URL actually works, then it would be
simplest to do just that, instead of a separate syntax check. Checking
that it works is of course nontrivial, especially since it may involve
dealing with redirections and temporary network and server problemn.
> You might consider using HTML5 pattern attribute where
> supported.
[...]
>> I've thought about testing to see if it contains at least 1 "." (since
>> all website addresses would, I think), but that's pretty vague; a less-
>> savvy person might enter their email address, and it would go through.
>> I guess that I could also check for an "@", but I can't help but
>> wonder if there's a smarter / smoother option?
>
> HTML5 INPUT type="email", feature tested, and with a fallback on the
> client where the test fails, and a fallback on the server (server side
> handling) where JS is disabled).
Pardon? This is place for using <input type=url>, isn't it? It's good to
use it even though most browsers will treat it as <input type=text>, so
that any client-side checks will be performed only if coded in
JavaScript and when JavaScript is enabled. (To be honest, there is a
risk in using <input type=url>, or <input type=email> for that matter -
it is useful when you specifically expect email address. The risk is
that when browsers start supporting them more widely, they will first do
it wildly. It's easy even to people who write browsers to produce code
that checks URLs and email addresses so that correct data is rejected
and incorrect data passes thru.)
--
Yucca,
http://www.cs.tut.fi/~jkorpela/