0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Rails validator for validating format of czech identification number = IC
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 4.1.0
 Project Readme

ico-validator

Build Status Dependency Status Code Climate Test Coverage

Ruby validator for format of Czech company identification number - ICO

Contains:

  1. Standalone ruby validator
  2. Rails ActiveModel::EachValidator
  3. JS validator

What is validated:

  1. ICO length - must be exactly 8 characters
  2. ICO must contain only numbers
  3. ICO number must satisfy last digit control formula

Usage

Ruby validator

Ruby validator is one simple module with only one public method IcoValidation.valid_ico? which returns true or false.

require 'ico_validator'

IcoValidation.valid_ico?('12345678') # invalid ico
=> false

IcoValidation.valid_ico?('27169278')
=> true

Rails validator

Rails validator is implemented as ActiveModel::EachValidator. So it's easy to use within your AR models:

class Company < ActiveRecord::Base
  validates :ico, ico: true
end

If validation doesn't pass it adds :invalid_format error on validated attribute.

JS validation

ico-validator is Rails engine, so if you want to validate ico with javascript just add following to application.js

//= require ico-validator

And then on any field you want to be validated with JS:

<%= form_for(...) do |f| %>
  <%= f.text_field :ico, class: 'ico-validate' %>
<% end %>

jQuery will bind validations there.