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