{"id":13484340,"url":"https://github.com/franckverrot/activevalidators","last_synced_at":"2025-04-08T10:33:09.391Z","repository":{"id":1196945,"uuid":"1103720","full_name":"franckverrot/activevalidators","owner":"franckverrot","description":"Collection of ActiveModel/ActiveRecord validators","archived":false,"fork":false,"pushed_at":"2023-10-29T16:51:27.000Z","size":293,"stargazers_count":305,"open_issues_count":3,"forks_count":49,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-04-13T22:57:01.545Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/activevalidators","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/franckverrot.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md"}},"created_at":"2010-11-22T22:00:27.000Z","updated_at":"2024-02-05T03:16:09.000Z","dependencies_parsed_at":"2024-01-05T21:59:53.844Z","dependency_job_id":null,"html_url":"https://github.com/franckverrot/activevalidators","commit_stats":{"total_commits":274,"total_committers":32,"mean_commits":8.5625,"dds":0.3868613138686131,"last_synced_commit":"ef6905401d869d9baabf9ccce5ede8fd603a3a8e"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/franckverrot%2Factivevalidators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/franckverrot%2Factivevalidators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/franckverrot%2Factivevalidators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/franckverrot%2Factivevalidators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/franckverrot","download_url":"https://codeload.github.com/franckverrot/activevalidators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247824140,"owners_count":21002212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:22.771Z","updated_at":"2025-04-08T10:33:09.349Z","avatar_url":"https://github.com/franckverrot.png","language":"Ruby","readme":"# ActiveValidators [![CircleCI](https://circleci.com/gh/franckverrot/activevalidators.svg?style=svg)](https://circleci.com/gh/franckverrot/activevalidators)\n\n# Description\n\nActiveValidators is a collection of off-the-shelf and tested ActiveModel/ActiveRecord validations.\n\n## Verify authenticity of this gem\n\nActiveValidators is cryptographically signed. Please make sure the gem you install hasn’t been tampered with.\n\nAdd my public key (if you haven’t already) as a trusted certificate:\n\n    gem cert --add \u003c(curl -Ls https://raw.githubusercontent.com/franckverrot/activevalidators/master/certs/franckverrot.pem)\n\n    gem install activevalidators -P MediumSecurity\n\nThe MediumSecurity trust profile will verify signed gems, but allow the installation of unsigned dependencies.\n\nThis is necessary because not all of ActiveValidators’ dependencies are signed, so we cannot use HighSecurity.\n\n## Requirements\n\n * Rails 5.1+\n * Ruby 2.4+\n\n## Installation\n\n    gem install activevalidators\n\nThis projects follows [Semantic Versioning a.k.a SemVer](http://semver.org). If you use Bundler, you can use the stabby specifier `~\u003e` safely.\n\nWhat it means is that you should specify an ActiveValidators version like this :\n\n```ruby\ngem 'activevalidators', '~\u003e 5.1.0' # \u003c-- mind the patch version\n```\n\nOnce you have `require`'d the gem, you will have to activate the validators you\nwant to use as ActiveValidators doesn't force you to use them all :\n\n```ruby\n# Activate all the validators\nActiveValidators.activate(:all)\n\n# Activate only the email and slug validators\nActiveValidators.activate(:email, :slug)\n\n# Activate only the phone\nActiveValidators.activate(:phone)\n```\n\n`ActiveValidators.activate` can be called as many times as one wants. It's only\na syntactic sugar on top a normal Ruby `require`.\n\nIn a standard Ruby on Rails application, this line goes either in an initializer\n(`config/initializers/active_validators_activation.rb` for example), or directly\nwithin `config/application` right inside your `MyApp::Application` class definition.\n\n## Usage\n\nIn your models, the gem provides new validators like `email`, or `url`:\n\n```ruby\nclass User\n  validates :company_siren, :siren       =\u003e true\n  validates :email_address, :email       =\u003e true # == :email =\u003e { :strict =\u003e false }\n  validates :link_url,      :url         =\u003e true # Could be combined with `allow_blank: true`\n  validates :password,      :password    =\u003e { :strength =\u003e :medium }\n  validates :postal_code,   :postal_code =\u003e { :country =\u003e :us }\n  validates :twitter,       :twitter     =\u003e true\n  validates :twitter_at,    :twitter     =\u003e { :format =\u003e :username_with_at }\n  validates :twitter_url,   :twitter     =\u003e { :format =\u003e :url }\n  validates :user_phone,    :phone       =\u003e true\nend\n\nclass Identification\n  validates :nino, :nino =\u003e true\n  validates :sin,  :sin  =\u003e true\n  validates :ssn,  :ssn  =\u003e true\nend\n\nclass Article\n  validates :slug,            :slug =\u003e true\n  validates :expiration_date, :date =\u003e {\n                                          :after =\u003e -\u003e (record) { Time.now },\n                                          :before =\u003e -\u003e (record) { Time.now + 1.year }\n                                        }\nend\n\nclass Device\n  validates :ipv4, :ip =\u003e { :format =\u003e :v4 }\n  validates :ipv6, :ip =\u003e { :format =\u003e :v6 }\nend\n\nclass Account\n  validates :any_card,        :credit_card =\u003e true\n  validates :visa_card,       :credit_card =\u003e { :type =\u003e :visa }\n  validates :credit_card,     :credit_card =\u003e { :type =\u003e :any  }\n  validates :supported_card,  :credit_card =\u003e { :type =\u003e [:visa, :master_card, :amex] }\nend\n\nclass Order\n  validates :tracking_num, :tracking_number =\u003e { :carrier =\u003e :ups }\nend\n\nclass Product\n  validates :code, :barcode =\u003e { :format =\u003e :ean13 }\nend\n```\n\nExhaustive list of supported validators and their implementation:\n\n* `barcode`   : based on known formats (:ean13 only for now)\n* `credit_card` : based on the [`credit_card_validations`](https://github.com/Fivell/credit_card_validations) gem\n* `date`  : based on the [`date_validator`](https://github.com/codegram/date_validator) gem\n* `email` : based on the [`mail`](https://github.com/mikel/mail) gem\n* `hex_color` : based on a regular expression\n* `ip`    : based on `Resolv::IPv[4|6]::Regex`\n* `nino` : National Insurance number (only for UK). Please note that this validation will not accept temporary (such as 63T12345) or administrative numbers (with prefixes like OO, CR, FY, MW, NC, PP, PY, PZ).\n* `password` : based on a set of regular expressions\n* `phone` : based on a set of predefined masks\n* `postal_code`: based on a set of predefined masks\n* `regexp` : uses Ruby's [`Regexp.compile`](http://www.ruby-doc.org/core-2.1.1/Regexp.html#method-c-new) method\n* `respond_to` : generic Ruby `respond_to`\n* `siren` : [SIREN](http://fr.wikipedia.org/wiki/SIREN) company numbers in France\n* `slug`  : based on `ActiveSupport::String#parameterize`\n* `sin` : Social Insurance Number (only for Canada). You may also allow permanent resident cards (such cards start with '9') or business numbers (such numbers start with '8'): `:sin =\u003e {:country =\u003e :canada, :country_options =\u003e {allow_permanent_residents: true, allow_business_numbers: true}}`\n* `ssn` : Social Security Number (only for USA).\n* `tracking_number`: based on a set of predefined masks\n* `twitter` : based on a regular expression\n* `url`   : based on a regular expression\n\n\n### Handling error messages\n\nThe validators rely on ActiveModel validations, and will require one to use its i18n-based mechanism. Here is a basic example:\n\n```ruby\n# user.rb\n\nclass User \u003c ActiveRecord::Base\n  validates :email, email: {message: :bad_email}\nend\n```\n\n```yaml\n# en.yml\n\nen:\n  activerecord:\n    errors:\n      models:\n        user:\n          attributes:\n            email:\n              bad_email: \"your error message\"\n```\n\n## Todo\n\nLots of improvements can be made:\n\n* Implement new validators\n* ...\n\n## Note on Patches/Pull Requests\n\n* Fork the project.\n* Make your feature addition or bug fix.\n* Add tests for it. This is important so I don't break it in a\n  future version unintentionally.\n* Commit, do not mess with rakefile, version, or history.\n  (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)\n* Send me a pull request. Bonus points for topic branches.\n\n\n## Contributors\n\nPlease checkout [AUTHORS.md](authors) to see who contributed.  Get involved!\n\n\n## Copyright\n\nCopyright (c) 2010-2018 Franck Verrot. MIT LICENSE. See LICENSE for details.\n\n[authors]: https://github.com/franckverrot/activevalidators/blob/master/AUTHORS.md\n","funding_links":[],"categories":["ORM/ODM Extensions","Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffranckverrot%2Factivevalidators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffranckverrot%2Factivevalidators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffranckverrot%2Factivevalidators/lists"}