Forum: Ruby on Rails validates_format_of :url, regexp?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
429500a5a54600958c9c7ac032a37f66?d=identicon&s=25 Joe (Guest)
on 2006-02-21 22:38
Hey,

Does anybody have a regexp for validating URLs? I found this one and am
trying to adapt it:

^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$

(http://www.experts-exchange.com/Web/Web_Languages/...)

I also found this one, but, um, well...
http://www.foad.org/~abigail/Perl/url3.regex
http://www.foad.org/~abigail/Perl/url2.html

Thanks,
Joe
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-02-22 18:34
(Received via mailing list)
Joe wrote:
> Hey,
>
> Does anybody have a regexp for validating URLs? I found this one and am
> trying to adapt it:
>
> 
^(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$
>
> (http://www.experts-exchange.com/Web/Web_Languages/...)
It depends what rules you're trying to validate against.  The simplest
thing to do is probably to use the regex from RFC 2396:

   (([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))

and then split out the component parts and validate them separately.
That way you can check that the server name has a reasonable tld, and
that the scheme matches something valid, and so on.  Check the rfc for
details.

>
> I also found this one, but, um, well...
> http://www.foad.org/~abigail/Perl/url3.regex
Ick!  Mind-bleach, quick!

--
Alex
2ddf351c22a32261a7b30e4d5ae3ab01?d=identicon&s=25 Adrien Kohlbecker (Guest)
on 2006-02-25 17:38
(Received via mailing list)
On 2/21/06, Joe <joe@yahoo.com> wrote:
> http://www.foad.org/~abigail/Perl/url3.regex
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

Hello,

You remembered me that I wanted to have a RFC-compliant URI regexp
Well, this is done now, I've just translated the RFC into some ruby
code to make a regexp string
See the attachement.
This topic is locked and can not be replied to.