Code Comments
Programming Forum and web based access to our favorite programming groups.how can i validate a field for a valid URL?? is ther any naming conventions for it?
Post Follow-up to this messageangie a écrit : > how can i validate a field for a valid URL?? is ther any naming > conventions for it? 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...=1&categoryId=2 Michael
Post Follow-up to this messageOn Apr 2, 2:46 pm, Michael DOUBEZ <michael.dou...@free.fr> wrote: > angie a =E9crit : > 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?cattabin=[/color ] dex=3D1&categoryId=3D2 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 ("news://comp.lang.c%2B%2B", 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"). -- James Kanze (GABI Software) email:james.kanze@gmail.com Conseils en informatique orient=E9e objet/ Beratung in objektorientierter Datenverarbeitung 9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
Post Follow-up to this messageJames Kanze a écrit :
> On Apr 2, 2:46 pm, Michael DOUBEZ <michael.dou...@free.fr> wrote:
>
>
>
> 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 ("news://comp.lang.c%2B%2B", 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:password@ftp.secure.com:245/path/to/data
Perhaps Boost.Spirit would be more fitting for capturing more complex
URI. At least It would be more manageable.
Michael
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.