<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Validating URL/URI in Ruby on Rails</title>
	<atom:link href="http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/</link>
	<description>A goal is a dream with a deadline.</description>
	<pubDate>Fri, 04 Jul 2008 03:03:47 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Henrik N</title>
		<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/#comment-104088</link>
		<dc:creator>Henrik N</dc:creator>
		<pubDate>Wed, 18 Jun 2008 14:59:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/07/validating-urluri-in-ruby-on-rails/#comment-104088</guid>
		<description>Ilya: Yeah, I noticed that when I tried it: it allowed e.g. "foo" and "http://foo"… Tried posting an update here but was unable to.</description>
		<content:encoded><![CDATA[<p>Ilya: Yeah, I noticed that when I tried it: it allowed e.g. &#8220;foo&#8221; and &#8220;http://foo&#8221;… Tried posting an update here but was unable to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/#comment-104083</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Wed, 18 Jun 2008 12:31:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/07/validating-urluri-in-ruby-on-rails/#comment-104083</guid>
		<description>Henrik, URI.parse uses a very similar regex, and if I remember correctly, it is actually more relaxed than the regular expression I suggested in the original post. Try running a few test URLs through both and then determine which one suits you best.</description>
		<content:encoded><![CDATA[<p>Henrik, URI.parse uses a very similar regex, and if I remember correctly, it is actually more relaxed than the regular expression I suggested in the original post. Try running a few test URLs through both and then determine which one suits you best.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henrik N</title>
		<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/#comment-104081</link>
		<dc:creator>Henrik N</dc:creator>
		<pubDate>Wed, 18 Jun 2008 10:23:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/07/validating-urluri-in-ruby-on-rails/#comment-104081</guid>
		<description>Rather than a regexp, how about just using URI.parse and rescue URI::InvalidURIError?</description>
		<content:encoded><![CDATA[<p>Rather than a regexp, how about just using URI.parse and rescue URI::InvalidURIError?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/#comment-100708</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Thu, 27 Dec 2007 04:57:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/07/validating-urluri-in-ruby-on-rails/#comment-100708</guid>
		<description>Awesome, thanks for sharing the fix Alan.</description>
		<content:encoded><![CDATA[<p>Awesome, thanks for sharing the fix Alan.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan Lake</title>
		<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/#comment-98679</link>
		<dc:creator>Alan Lake</dc:creator>
		<pubDate>Sun, 16 Dec 2007 00:56:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/07/validating-urluri-in-ruby-on-rails/#comment-98679</guid>
		<description>I messed with the regexp some more and came up with something that passed all of our tests.  It is:
&lt;code&gt;validates_uri_existence_of :url, 
                             :if         =&gt; Proc.new {&#124;u&#124; !u.page.blank? },
                             :allow_nil  =&gt; true,
                             :with =&gt; /(^(http&#124;https):\/\/[a-z0-9]+([-.]{1}[a-z0-9]*)+. [a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I messed with the regexp some more and came up with something that passed all of our tests.  It is:<br />
<code>validates_uri_existence_of :url,<br />
                             :if         => Proc.new {|u| !u.page.blank? },<br />
                             :allow_nil  => true,<br />
                             :with => /(^(http|https):\/\/[a-z0-9]+([-.]{1}[a-z0-9]*)+. [a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan Lake</title>
		<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/#comment-98478</link>
		<dc:creator>Alan Lake</dc:creator>
		<pubDate>Fri, 14 Dec 2007 20:12:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/07/validating-urluri-in-ruby-on-rails/#comment-98478</guid>
		<description>I'm getting a failure where I should not (my web site).  I'd appreciate help in fixing it.  The only modification that I need is to allow the field to be blank.  I'm not really comfortable with regexps, although I think I can read them.  I don't understand the "ix" at the end of it.  Here's what I have in my models code:
  validates_uri_existence_of :page, 
                             :with =&#62; /(^$)&#124;(^(http&#124;https):\/\/[a-z0-9] ([-.]{1}[a-z0-9] )*.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix,
                             :if         =&#62; Proc.new {&#124;u&#124; !u.page.blank? },
                             :allow_nil  =&#62; true
Thanx</description>
		<content:encoded><![CDATA[<p>I&#8217;m getting a failure where I should not (my web site).  I&#8217;d appreciate help in fixing it.  The only modification that I need is to allow the field to be blank.  I&#8217;m not really comfortable with regexps, although I think I can read them.  I don&#8217;t understand the &#8220;ix&#8221; at the end of it.  Here&#8217;s what I have in my models code:<br />
  validates_uri_existence_of :page,<br />
                             :with =&gt; /(^$)|(^(http|https):\/\/[a-z0-9] ([-.]{1}[a-z0-9] )*.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix,<br />
                             :if         =&gt; Proc.new {|u| !u.page.blank? },<br />
                             :allow_nil  =&gt; true<br />
Thanx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/#comment-93817</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Thu, 29 Nov 2007 07:43:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/07/validating-urluri-in-ruby-on-rails/#comment-93817</guid>
		<description>Adam, that's definitely a good idea. Having said that, you don't need to waste space in your database by always keeping the redundant http:// part. Instead, I would recommend stripping it away and then appending it when you display the link back to the user.</description>
		<content:encoded><![CDATA[<p>Adam, that&#8217;s definitely a good idea. Having said that, you don&#8217;t need to waste space in your database by always keeping the redundant <a href="http://" rel="nofollow">http://</a> part. Instead, I would recommend stripping it away and then appending it when you display the link back to the user.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/#comment-93130</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Tue, 27 Nov 2007 23:23:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/07/validating-urluri-in-ruby-on-rails/#comment-93130</guid>
		<description>Nice work. What if rather than validating that user entered correct URL, you simply created a valid URL for the user. That is, if user supplies "http://www.yahoo.com" you do nothing. If they supply "yahoo.com" you add "http://"</description>
		<content:encoded><![CDATA[<p>Nice work. What if rather than validating that user entered correct URL, you simply created a valid URL for the user. That is, if user supplies &#8220;http://www.yahoo.com&#8221; you do nothing. If they supply &#8220;yahoo.com&#8221; you add &#8220;http://&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alan Lake</title>
		<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/#comment-92041</link>
		<dc:creator>Alan Lake</dc:creator>
		<pubDate>Sun, 25 Nov 2007 17:21:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/07/validating-urluri-in-ruby-on-rails/#comment-92041</guid>
		<description>Thank you, Ilya!</description>
		<content:encoded><![CDATA[<p>Thank you, Ilya!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/#comment-92028</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Sun, 25 Nov 2007 16:17:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/07/validating-urluri-in-ruby-on-rails/#comment-92028</guid>
		<description>Alan, not sure what happened with the code there, but you're right, that won't run! Here is what it should read instead:

&lt;code&gt;
configuration = { :message =&gt; "is not valid or not responding", :on =&gt; :save, :with =&gt; nil }
    configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Alan, not sure what happened with the code there, but you&#8217;re right, that won&#8217;t run! Here is what it should read instead:</p>
<p><code><br />
configuration = { :message => "is not valid or not responding", :on => :save, :with => nil }<br />
    configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)<br />
</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>
