Validate a URI string attribute
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config/locales
lib
spec
.coverrails.yml
.gitignore
.travis.yml
Gemfile
README.md
Rakefile
activemodel-url_validator.gemspec

README.md

activemodel-url_validator

Build Status Code Climate Coverage Status Dependency Status

Usage

Add to your Gemfile:

gem 'activemodel-url_validator'

Run:

bundle install

Then add the following to your model:

validates :my_url_attribute, url: true

Custom options

Name Value Default Desc.
scheme Array of String nil Specify allowed scheme types.
allow_no_scheme Boolean false Whether scheme less URI is allowed.
allow_no_host Boolean false Whether host less URI is allowed.
validates :my_url_attribute, url: { scheme: ['https'] }

Validation outside a model

If you need to validate a url outside a model, you can do that:

UrlValidator.valid?(string, options)