0.0
No commit activity in last 3 years
No release in over 3 years
Rails Validations for typically UK specific data
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.3
>= 0

Runtime

 Project Readme

UK Validators

This library contains Rails 3 custom validators for the following UK-centric data:

  • National Insurance Number
  • Post Code
  • Driving Licence Number
  • Passport Number

Installation

Add this line to your application's Gemfile:

gem 'uk_validators'

And then execute:

$ bundle install

National Insurance Number (Nino)

Validates the format of a UK National Insurance Number.

References: HMRC, uk-osint.net, Wikipedia

Usage

class User < ActiveRecord::Base
  validates :ni_number, nino: true
end

I18n

The default error message is is not a valid National Insurance No.

This can be translated in the same was as any other Rails validation message using the key :nino.

For the example User model above, the customised en.yml would be:

en:
  activerecord:
    errors:
      models:
        user:
          attributes:
            ni_number:
              nino: "is not valid"

Post Code

Validates the format of a UK postal code. This does not check whether the post code actually exists as this would require a lookup against approx. 1.8 million postal codes.

References: Royal Mail PAF Document, Wikipedia

Usage

class Address < ActiveRecord::Base
  validates :postal_code, postcode: true
end

I18n

The default error message is is not a valid postcode

This can be translated in the same was as any other Rails validation message using the key :postcode.

For the example Address model above, the customised en.yml would be:

en:
  activerecord:
    errors:
      models:
        address:
          attributes:
            postal_code:
              postcode: "is not valid"

Driving Licence Number

Validates the format of a UK Driving Licence Number covering the format used in England, Scotland and Wales. Northen Ireland has a different format containing 8 random alphanumeric characters.

References: DVLA, uk-osint.net

Usage

class User < ActiveRecord::Base
  validates :licence_number, driving_licence: true
end

I18n

The default error message is is not a valid Driving Licence No.

This can be translated in the same was as any other Rails validation message using the key :driving_licence.

For the example User model above, the customised en.yml would be:

en:
  activerecord:
    errors:
      models:
        user:
          attributes:
            licence_number:
              driving_licence: "is not valid"

Passport Number

A UK passport number is simply made up of 9 numeric characters.

References: NHS Data Dictionary, highprogrammer.com

Usage

class HolidayMaker < ActiveRecord::Base
  validates :passport, passport_number: true
end

I18n

The default error message is is not a valid Passport No.

This can be translated in the same was as any other Rails validation message using the key :passport_number.

For the example HolidayMaker model above, the customised en.yml would be:

en:
  activerecord:
    errors:
      models:
        holiday_maker:
          attributes:
            passport:
              passport_number: "is not valid"

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