naming convention

A

angie

how can i validate a field for a valid URL?? is ther any naming
conventions for it?
 
J

James Kanze

angie a écrit :
Same as for your question about identifying the IP address.
You can check again a regex (there are many already done out there).
A good starting point is:http://regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2

Except that a regular expression which accepts all syntactically
valid URL's, and rejects all syntactically invalid ones, is far
from trivial; the one you cite, for example, will reject a lot
of legal URL's ("for example:), and
accept a few illegal ones (e.g. "www."). I pretty sure it can
be done with a regular expression, but it will take a bit of
work to get it right. (Note too that different types of URL's
may have slightly different syntax. If the protocol is
"mailto", for example, a '@' is required at one point, whereas
if it is "http", one may not appear unless quoted somehow (e.g.
"%40").
 
M

Michael DOUBEZ

James Kanze a écrit :
Except that a regular expression which accepts all syntactically
valid URL's, and rejects all syntactically invalid ones, is far
from trivial; the one you cite, for example, will reject a lot
of legal URL's ("for example:), and
accept a few illegal ones (e.g. "www."). I pretty sure it can
be done with a regular expression, but it will take a bit of
work to get it right.

Yes. That is why I provided the link to a regex library instead of
giving a specific regex. The site indicate what URI are accepted or
rejected depending on the regex used.
(Note too that different types of URL's
may have slightly different syntax. If the protocol is
"mailto", for example, a '@' is required at one point, whereas
if it is "http", one may not appear unless quoted somehow (e.g.
"%40").

Or ftp that uses @ to separate the username/password from the actual
address:
ftp://john_dow:p[email protected]:245/path/to/data

Perhaps Boost.Spirit would be more fitting for capturing more complex
URI. At least It would be more manageable.

Michael
 
J

James Kanze

James Kanze a écrit :
Yes. That is why I provided the link to a regex library
instead of giving a specific regex. The site indicate what URI
are accepted or rejected depending on the regex used.

If the goal is to use a regular expression library, boost::regex
is clearly indicated, except in very special cases. I say this
as someone who has made available a regular expression
library---use Boost's, instead of mine, except in special cases.
(I'm still maintaining mine, but mainly in view of supporting a
few special cases, especially generating the regular expression
as compilable static data, which Boost doesn't support.)
Or ftp that uses @ to separate the username/password from the actual
address:
ftp://john_dow:p[email protected]:245/path/to/data
Perhaps Boost.Spirit would be more fitting for capturing more
complex URI. At least It would be more manageable.

In a sense, there is no solution, because the actual syntax
depends on the protocol, and protocols can be added at any time.
Typically, of course, you don't care: if you can't handle the
protocol (and you can't handle those you don't know about), then
the URL is illegal, as far as you're concerned. So I'd say use
std::find to get the position of the first ':', consider
everything up to that to be the protocol, and use a regular
expression to handle the rest, depending on the protocol.

Just be aware that you have to read the standard concerning the
protocol very carefully, and that the regular expression might
not be that obvious, but needs to be very carefully thought out.
With things like "([[:alnum:]...]|%[:xdigit:][:xdigit:])+",
instead of simply "[:alnum:]+".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top