HTTP URL validation
A post by Nathaniel Steven on Ruby on Rails list caught my eye. He was answering a question for someone asking for HTTP URL validation plugin.
He suggests to add the following regular expression "as a define
or even as a helper to AR in the format of "validates_format_of_url
:url" to be a shorthand for the REGEX."
class Company < ActiveRecord::Base
validates_format_of :url, :with =>
/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
end
Thank you Nathaniel for sharing this.
Frank
0 Comments:
Post a Comment
<< Home