Collection of ActiveModel/ActiveRecord validators
ActiveValidators is a collection of off-the-shelf and tested ActiveModel/ActiveRecord validations.
gem install activevalidators
This projects follows Semantic Versioning a.k.a SemVer. If you use Bundler, you can use the stabby specifier ~>
safely.
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:
credit_card
: based on the Luhn
algorithmdate
: based on the DateValidator
gememail
: based on the mail
gemip
: based on Resolv::IPv[4|6]::Regex
password
: based on a set of regular expressionsphone
: based on a set of predefined maskspostal_code
: based on a set of predefined masksrespond_to
slug
: based on ActiveSupport::String#parameterize
tracking_number
: based on a set of predefined maskstwitter
: based on a regular expressionurl
: based on a regular expressionLots of improvements can be made:
Copyright (c) 2010-2011 Franck Verrot. MIT LICENSE. See LICENSE for details.