Module: DataMapper::Validations::Format::Url

Included in:
DataMapper::Validations::FormatValidator
Defined in:
lib/dm-validations/formats/url.rb

Constant Summary collapse

Url =
begin
  # Regex from http://www.igvita.com/2006/09/07/validating-url-in-ruby-on-rails/
  /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}((\:[0-9]{1,5})?\/?.*)?$)/ix
end

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/dm-validations/formats/url.rb', line 8

def self.included(base)
  DataMapper::Validations::FormatValidator::FORMATS.merge!(
    :url => [
      Url,
      lambda { |field, value|
        '%s is not a valid URL'.t(value)
      }
    ]
  )
end