Validates_format_of :url, regexp?

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.,;?'\+&%$#=~_-]+))$

(Solved: URL Regular Expression | Experts Exchange)

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

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.,;?'\+&%$#=~_-]+))$

(Solved: URL Regular Expression | Experts Exchange)
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

On 2/21/06, Joe [email protected] 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.