URL Regex
A regular expression pattern that validates a URL string, either HTTP or HTTPS.
1 2 /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
You can easily use it with validates_format_of in your Model...
For example, In a comment model, to check the :SiteURL on the comment creation:
1 2 class Comment < ActiveRecord::Base 3 validates_format_of :SiteURL, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix, :on => :create 4 end