No commit activity in last 3 years
No release in over 3 years
It provides validators for national identification numbers
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 0
~> 0
~> 3.0
 Project Readme

Gem Version Build Status Coverage Status

National IDs Validator for Ruby on Rails (Active Model)

It provides validators for national identification numbers. Currently the following countries are supported:

  • Norway (NO) - Fødselsnummer
  • Poland (PL) - PESEL

Usage

Add to your Gemfile:

gem 'national-ids-validator'

Run:

bundle install

Then add the following to your model:

require 'national_ids_validator'
validates :personal_id_attribute, :national_id => {country: "PL"}

Options

A custom error message can be provided:

require 'national_ids_validator'
validates :personal_id_attribute, :national_id => {country: "PL", message: "is not valid personal number"}

If the nil value should be allowed, it need to be explicitely stated:

require 'national_ids_validator'
validates :personal_id_attribute, :national_id => {country: "PL", allow_nil: true}

Retrieving data out of the personal number

Often personal number contains useful data like birth date and/or gender. You may use the following commands to retrieve them:

  • gender
require 'national_ids_validator'
NationalIdsValidator.new("12030599592", "NO").gender %returns 0

It will return 0 for man, 1 for woman and nil for invalid number.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Credit

Based on https://github.com/balexand/email_validator and https://github.com/max-power/iban.

License

MIT License. Copyright 2009-2014 Grzegorz Brzezinka. http://brzezinka.eu