Container Number Validator
This gem allows you to easily validate container number fields to be valid container numbers.
It validates Container Number according to ISO_6346
NYKU5824120
Also supports format where checkdigit is seperated with a dash like this
NYKU582412-0
Installation
Add this line to your application's Gemfile:
gem 'container_number_validator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install container_number_validator
Usage
ContainerNumberValidator.validate('NYKU582412-0')
#=> true
ContainerNumberValidator.validate('NYKU582412-3')
#=> false
Rails 3.x / 4.x
You can use ContainerNumberValidator with any ActiveModel class, including ActiveRecord models:
class Container < ActiveRecord::Base
validates :container_no, container_number: true
end
Edge cases
- When no container number is present (or set to
nil
), all container numbers are considered INVALID.
Contributing
Wishlist
- Make 10 checksum result configurable
If you're unsure what to contribute, contact me. :-)
How to contribute
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
License
See LICENSE.txt