Add format validation to link.rb

This commit is contained in:
chris 2013-10-31 14:09:59 +08:00
parent 00010867a4
commit 68e12fd737
1 changed files with 1 additions and 3 deletions

View File

@ -2,10 +2,8 @@ class Link < Item
field :url, localize: true
validates :url, at_least_one: true
validates :url, at_least_one: true, :format => /^(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|localhost(:[0-9]{1,5})?(\/.*)?/i
# validates :url, :presence => true, :format => /^(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|localhost(:[0-9]{1,5})?(\/.*)?/i
before_validation :add_http
def link