ActiveValidators

Collection of ActiveModel/ActiveRecord validators

View the Project on GitHub franckverrot/activevalidators

ActiveValidators Travis

Description

ActiveValidators is a collection of off-the-shelf and tested ActiveModel/ActiveRecord validations.

Installation

gem install activevalidators

This projects follows Semantic Versioning a.k.a SemVer. If you use Bundler, you can use the stabby specifier ~> safely.

Usage

In your models, the gem provides new validators like email, or url:

```ruby class User validates :emailaddress, :email => true validates :linkurl, :url => true validates :userphone, :phone => true validates :password, :password => { :strength => :medium } validates :twitterat, :twitter => { :format => :usernamewithat } validates :twitterurl, :twitter => { :format => :url } validates :twitter, :twitter => true validates :postalcode, :postal_code => { :country => :us } end

class Article
  validates :slug,          :slug => true
  validates :expiration_date,
                  :date => {
                             :after => lambda { Time.now },
                             :before => lambda { Time.now + 1.year }
                           }
end

class Device
  validates :ipv6,          :ip => { :format => :v6 }
  validates :ipv4,          :ip => { :format => :v4 }
end

class Account
  validates :any_card,      :credit_card => true
  validates :visa_card,     :credit_card => { :type => :visa }
  validates :credit_card,   :credit_card => { :type => :any  }
end

class Order
  validates :tracking_num,  :tracking_number => { :carrier => :ups }
end

```

Exhaustive list of supported validators and their implementation:

Todo

Lots of improvements can be made:

Note on Patches/Pull Requests

Contributors

Copyright

Copyright (c) 2010-2011 Franck Verrot. MIT LICENSE. See LICENSE for details.