A collection of delicious Rails validators
No matter what app you are working on, Rails never seems to include all the validations you need, and you end having to repeat yourself over and over by writing regex validations and/or custom validators.
Validatious solves this problem by packaging up all these often used, but missing Rails validators, into one single RubyGem.
The best way to install Validatious is with RubyGems:
$ [sudo] gem install validatious
If you're installing from source, you can use Bundler to pick up all the gems:
$ bundle install # ([more info](http://gembundler.com/bundle_install.html))
All the validators in Validatious are designed to work with Rails 3 and up, and take advantage of ActiveModel::Validator. This means that they are all used in the usual Rails way:
validates :url, :url => true
The old Rails 2 style validations are also supported:
validates_url_format_of :url
Validatious currently provides the following validators:
This validates the format of a URL, ensuring that the attribute conforms to the correct format of a URL.
validates :url, :url => true
or
validates_url_format_of :url
This validates the format of an email address, ensuring that the attribute conforms to the correct format of an email address.
validates :email, :email => true
or
validates_email_format_of :email
This validates the format of a postal code address, ensuring that the attribute conforms to the correct format as specified by the given country (default: US).
validates :zip, :postal_code => true
or specify a different country
validates :zip, :postal_code => { :country => 'UK' }
or validate for several countries
validates :zip, :postal_code => { :country => [ 'US', 'CA' ] }
or
validates_postal_code_format_of :zip
Extracted from validates_text_content, this validates the content of a text attribute, to determine whether or not a block of English text meets certain quality standards.
validates :comment, :text_content => true
or
validates_text_content_of :comment
Rejects:
Accepts:
If you'd like to hack on Validatious, start by forking my repo on GitHub:
http://github.com/joelmoss/validatious
To get all of the dependencies, install the gem first. The best way to get your changes merged back into core is as follows:
rake