From 68e12fd7370c5557321e8fe7d8b22ab87fa3d2cd Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 31 Oct 2013 14:09:59 +0800 Subject: [PATCH] Add format validation to link.rb --- app/models/link.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/link.rb b/app/models/link.rb index 5246e330..c7e14d7e 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -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