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:

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

Options

A custom error message can be provided:

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:

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 ruby 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