This gem allows you to easily valdiate license plate fields to be valid license plates.
We're planning on supporting multiple countries, but at this time we can only validate Dutch and German license plates.
Validates Dutch license plates ("kentekens"), includes all ten common Dutch license plate types.
Special license plates (like those for the Royal family) are not supported.
Also supports most german license plates, including most diplomatic formats.
Add this line to your application's Gemfile:
gem 'license_plate_validator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install license_plate_validator
LicensePlateValidator.new("60-NFH-1", country: :nl).valid?
#=> true
LicensePlateValidator.new("SBA 5226", country: :nl).valid?
#=> false
You can use LicensePlateValidator with any ActiveModel class, including ActiveRecord models:
class Vehicle < ActiveRecord::Base
validates :license_plate_number, license_plate: { country: :nl }
end
If you supply a Proc
it will be called with the current record begin validated.
The Proc
must return either nil
(accept all the things) or a valid country code.
class Vehicle < ActiveRecord::Base
validates :license_plate_number,
license_plate: { country: Proc.new { |vehicle| vehicle.country } }
end
- When no country is selected (or set to
nil
), all plates are considered valid. - When an unknown country is selected, all plates are considered valid (e.g. we assume there are no validation rules for that country)
:nl
Netherlands; all common "sidecode" number formats.:de
Germany; all regular forms as well as the common diplomatic variants
Locales for English, Dutch and German are provided. See lib/license_plate_validator/locales
for details.
I'd like to add the following feature (in no specific order), maybe you can help?
- Validate uncommon license plates as well (like CD-dd-dd and AA-dd)
- Check if characters used are actually allowed.
- Output properly formatted license plate numbers
- Add support for other countries where possible. Germany, Belgium, France and Poland are high on the list.
If you're unsure what to contribute, contact me. :-)
I prefer a pull request with added, but failing, specs to code without specs.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
- Pascal Widdershoven - for the original regexes for Dutch license plate numbers.
- Edward Poot - for adding new RDW approved license plate schemes
- Marcus Ilgner, evopark - for german license plates
See LICENSE.txt