<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: RegularExpression code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 07:03:59 GMT</pubDate>
    <description>DZone Snippets: RegularExpression code</description>
    <item>
      <title>URL Regex</title>
      <link>http://snippets.dzone.com/posts/show/3654</link>
      <description>// description of your code here&lt;br /&gt;A regular expression pattern that validates a URL string, either HTTP or HTTPS.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;You can easily use it with validates_format_of in your Model...&lt;br /&gt;&lt;br /&gt;For example, In a comment model, to check the :SiteURL on the comment creation:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Comment &lt; ActiveRecord::Base&lt;br /&gt;    validates_format_of :SiteURL, :with =&gt; /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix, :on =&gt; :create&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Sat, 10 Mar 2007 07:54:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3654</guid>
      <author>igeek (Geek)</author>
    </item>
  </channel>
</rss>
