Giter Club home page Giter Club logo

activevalidators's Introduction

ActiveValidators Travis

Collection of ActiveModel/ActiveRecord validations

Installation (Rails 3)

In your Gemfile ( >>= 1.1.0 ):

gem 'activevalidators'

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

    class User
      validates :email_address, :email => true
      validates :link_url,      :url   => true
      validates :user_phone,    :phone => true
      validates :password,      :password => { :strength => :medium }
      validates :twitter_at,    :twitter => { :format => :username_with_at }
      validates :twitter_url,   :twitter => { :format => :url }
      validates :twitter,       :twitter => true
      validates :postal_code,   :postal_code => { :format => :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 algorithm
  • date : based on the DateValidator gem
  • email : based on the mail gem
  • ip : based on Resolv::IPv[4|6]::Regex
  • password : based on a set of regular expressions
  • phone : based on a set of predefined masks
  • postal_code: based on a set of predefined masks
  • respond_to
  • slug : based on ActiveSupport::String#parameterize
  • tracking_number: based on a set of predefined masks
  • twitter : based on a regular expression
  • url : based on a regular expression

Todo

Lots of improvements can be made:

  • Implement new validators
  • ...

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Contributors

  • Franck Verrot
  • Oriol Gual
  • Paco Guzmán
  • Garrett Bjerkhoel
  • Renato Riccieri Santos Zannon
  • Brian Moseley
  • Travis Vachon
  • Rob Zuber

Copyright

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

activevalidators's People

Contributors

bcm avatar dewski avatar franckverrot avatar oriolgual avatar pacoguzman avatar renato-zannon avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.