Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0
2.7.1
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
dl_validator (0.0.7)
dl_validator (0.1.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -34,7 +34,7 @@ PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.3)
bundler
dl_validator!
rake
shoulda
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Andrew Medeiros, andrew@amedeiros.com, @_AndrewMedeiros

## Contributors
[crstamps2](https://github.com/crstamps2)
[mrryanjohnston](https://github.com/mrryanjohnston)

## Future

Expand Down
2 changes: 1 addition & 1 deletion dl_validator.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '~> 1.3'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'shoulda'
spec.add_development_dependency 'test-unit'
Expand Down
12 changes: 6 additions & 6 deletions lib/config/dl_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class DlConfig

# Constant frozen hash of regular expressions to validate a drivers license by state
STATES_REGEX = {
'AL' => /^[0-9]{1,7}$/, # Format: 1-7Numeric
'AL' => /^[0-9]{1,8}$/, # Format: 1-8Numeric
'AK' => /^[0-9]{1,7}$/, # Format: 1-7Numeric
'AZ' => /(^[A-Z]{1}[0-9]{1,8}$)|(^[A-Z]{2}[0-9]{2,5}$)|(^[0-9]{9}$)/, # Format: 1Alpha+1-8Numeric or 2Alpha+2-5Numeric or 9Numeric
'AZ' => /^([A-Z]{1}[0-9]{8}|[0-9]{9})$/, # Format: 1 Alpha + 8 Numeric OR 9 Numeric
'AR' => /^[0-9]{4,9}$/, # Format: 4-9Numeric
'CA' => /^[A-Z]{1}[0-9]{7}$/, # Format: 1Alpha+7Numeric
'CO' => /(^[0-9]{9}$)|(^[A-Z]{1}[0-9]{3,6}$)|(^[A-Z]{2}[0-9]{2,5}$)/, # Format: 9Numeric or 1Alpha+3-6Numeric or 2Alpha+2-5Numeric
Expand All @@ -73,7 +73,7 @@ class DlConfig
'ID' => /(^[A-Z]{2}[0-9]{6}[A-Z]{1}$)|(^[0-9]{9}$)/, # Format: 2Alpha+6Numeric+1Alpha or 9Numeric
'IL' => /^[A-Z]{1}[0-9]{11,12}$/, # Format: 1Alpha+11Numeric or 1Alpha+12Numeric
'IN' => /(^[A-Z]{1}[0-9]{9}$)|(^[0-9]{9,10}$)/, # Format: 1Alpha+9Numeric or 9Numeric or 10Numeric
'IA' => /(^[0-9]{9}$)|(^[0-9]{3}[A-Z]{2}[0-9]{4})$/, # Format: 9Numeric or 3Numeric+2Alpha+4Numeric
'IA' => /(^[0-9]{9}$)|(^[0-9]{3}[A-Z]{2}[0-9]{4})$/, # Format: 9Numeric or 3Numeric+2Alpha+4Numeric
'KS' => /(^([A-Z]{1}[0-9]{1}){2}[A-Z]{1}$)|(^[A-Z]{1}[0-9]{8}$)|(^[0-9]{9}$)/, # Format: 1Alpha+1Numeric+1Alpha+1Numeric+1Alpha or 1Alpha+8Numeric or 9Numeric
'KY' => /(^[A-Z]{1}[0-9]{8,9}$)|(^[0-9]{9}$)/, # Format: 1Alpha+8Numeric or 1Alpha+9Numeric or 9Numeric
'LA' => /^[0-9]{1,9}$/, # Format: 1-9Numeric
Expand All @@ -85,12 +85,12 @@ class DlConfig
'MS' => /^[0-9]{9}$/, # Format: 9Numeric
'MO' => /(^[A-Z]{1}[0-9]{5,9}$)|(^[A-Z]{1}[0-9]{6}[R]{1}$)|(^[0-9]{8}[A-Z]{2}$)|(^[0-9]{9}[A-Z]{1}$)|(^[0-9]{9}$)/, # Format: 1Alpha+5-9Numeric or 1Alpha+6Numeric+R or 8Numeric+2Alpha or 9Numeric+1Alpha or 9Numeric
'MT' => /(^[A-Z]{1}[0-9]{8}$)|(^[0-9]{13}$)|(^[0-9]{9}$)|(^[0-9]{14}$)/, # Format: 1Alpha+8Numeric or 13Numeric or 9Numeric or 14Numeric
'NE' => /^[0-9]{1,7}$/, # Format: 1-7Numeric
'NE' => /^[A-Z]{1}[0-9]{6,8}$/, # Format: 1Alpha+6-8Numeric
'NV' => /(^[0-9]{9,10}$)|(^[0-9]{12}$)|(^[X]{1}[0-9]{8}$)/, # Format: 9Numeric or 10Numeric or 12Numeric or X+8Numeric
'NH' => /^[0-9]{2}[A-Z]{3}[0-9]{5}$/, # Format: 2Numeric+3Alpha+5Numeric
'NJ' => /^[A-Z]{1}[0-9]{14}$/, # Format: 1Alpha+14Numeric
'NY' => /(^[A-Z]{1}[0-9]{7}$)|(^[A-Z]{1}[0-9]{18}$)|(^[0-9]{8}$)|(^[0-9]{9}$)|(^[0-9]{16}$)|(^[A-Z]{8}$)/, # Format: 1Alpha+7Numeric or 1Alpha+18Numeric or 8Numeric or 9Numeric or 16 Numeric or 8Alpha
'NM' => /^[0-9]{8,9}$/, # Format: 8Numeric or 9Numeric
'NY' => /(^[A-Z]{1}[0-9]{7}$)|(^[A-Z]{1}[0-9]{18}$)|(^[0-9]{8}$)|(^[0-9]{9}$)|(^[0-9]{16}$)|(^[A-Z]{8}$)/, # Format: 1Alpha+7Numeric or 1Alpha+18Numeric or 8Numeric or 9Numeric or 16 Numeric or 8Alpha
'NC' => /^[0-9]{1,12}$/, # Format: 1-12Numeric
'ND' => /(^[A-Z]{3}[0-9]{6}$)|(^[0-9]{9}$)/, # Format: 3Alpha+6Numeric or 9Numeric
'OH' => /(^[A-Z]{1}[0-9]{4,8}$)|(^[A-Z]{2}[0-9]{3,7}$)|(^[0-9]{8}$)/, # Format: 1Alpha+4-8Numeric or 2Alpha+3-7Numeric or 8Numeric
Expand All @@ -104,7 +104,7 @@ class DlConfig
'TX' => /^[0-9]{7,8}$/, # Format: 7-8Numeric
'UT' => /^[0-9]{4,10}$/, # Format: 4-10Numeric
'VT' => /(^[0-9]{8}$)|(^[0-9]{7}[A]$)/, # Format: 8Numeric or 7Numeric+A
'VA' => /(^[A-Z]{1}[0-9]{9,11}$)|(^[0-9]{9}$)/, # Format: 1Alpha+9Numeric or 1Alpha+10Numeric or 1Alpha+11Numeric or 9Numeric
'VA' => /(^[A-Z]{1}[0-9]{8,11}$)|(^[0-9]{9}$)/, # Format: 1Alpha+8-to-11Numeric or 9Numeric
'WA' => /^(?=.{12}$)[A-Z]{1,7}[A-Z0-9\*]{4,11}$/, # Format: 1-7Alpha+any combination of Alpha, Numeric, or * for a total of 12 characters
'WV' => /(^[0-9]{7}$)|(^[A-Z]{1,2}[0-9]{5,6}$)/, # Format: 7Numeric or 1-2Alpha+5-6Numeric
'WI' => /^[A-Z]{1}[0-9]{13}$/, # Format: 1Alpha+13Numeric
Expand Down
8 changes: 2 additions & 6 deletions lib/dl_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ def self.invalid?(dl_number, dl_state)
# This is moved out into a method to make unit testing easier.
def self.get_abbreviation_key(dl_state)
# If the dl_state is greater than 2 then it is a full state name and we need to find the corresponding abbreviation for that state.
key = ''
if dl_state.length > 2
DlConfig::STATES.each do |k, v|
key = k if v == dl_state
end
DlConfig::STATES.key(dl_state)
else
key = dl_state # The dl_state is already an abbreviated state
dl_state # The dl_state is already an abbreviated state
end
key
end

# Inverse of invalid?
Expand Down
2 changes: 1 addition & 1 deletion lib/dl_validator/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DlValidator
VERSION = '0.0.7'
VERSION = '0.1.0'
end
8 changes: 4 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
class Helper

VALID_DRIVERS_LICENSES = {
'AL' => ['1234567'], # Format: 1-7Numeric
'AL' => ['12345678'], # Format: 1-8Numeric
'AK' => ['1234567'], # Format: 1-7Numeric
'AZ' => ['A12345678', 'AA12345', '123456789'], # Format: 1Alpha+1-8Numeric or 2Alpha+2-5Numeric or 9Numeric
'AZ' => ['A12345678', '123456789'], # Format: 1Alpha + 8Numeric or 9Numeric
'AR' => ['1234', '123456789'], # Format: 4-9Numeric
'CA' => ['c1234567'], # Format: 1Alpha+7Numeric
'CO' => ['123456789', 'A123', 'A123456', 'AA12', 'AA12345'], # Format: 9Numeric or 1Alpha+3-6Numeric or 2Alpha+2-5Numeric
Expand All @@ -32,7 +32,7 @@ class Helper
'MS' => ['123456789'], # Format: 9Numeric
'MO' => ['M12345', 'A123456789', 'M123456R' , '12345678AB', '123456789A', '123456789'], # Format: 1Alpha+5-9Numeric or 1Alpha+6Numeric+R or 8Numeric+2Alpha or 9Numeric+1Alpha or 9Numeric
'MT' => ['J12345678', '1234567890123', '123456789', '12345678901234'], # Format: 1Alpha+8Numeric or 13Numeric or 9Numeric or 14Numeric
'NE' => ['1234567'], # Format: 1-7Numeric
'NE' => ['A123456', 'A1234567', 'A12345678'], # Format: 1Alpha+6-8Numeric
'NV' => ['123456789', '1234567890', '123456789012', 'X12345678'], # Format: 9Numeric or 10Numeric or 12Numeric or X+8Numeric
'NH' => ['12ADF12345'], # Format: 2Numeric+3Alpha+5Numeric
'NJ' => ['F12345678901234'], # Format: 1Alpha+14Numeric
Expand All @@ -51,7 +51,7 @@ class Helper
'TX' => ['1234567', '12345678'], # Format: 7-8Numeric
'UT' => ['1234', '1234567890'], # Format: 4-10Numeric
'VT' => ['12345678', '1234567A'], # Format: 8Numeric or 7Numeric+A
'VA' => ['K123456789', 'A1234567890', 'A12345678901', '123456789'], # Format: 1Alpha+9Numeric or 1Alpha+10Numeric or 1Alpha+11Numeric or 9Numeric
'VA' => ['A12345678', 'K123456789', 'A1234567890', 'A12345678901', '123456789'], # Format: 1Alpha+8-to-11Numeric or 9Numeric
'WA' => ['A12345678901', 'ABCDEFG12345'], # Format: 1-7Alpha+any combination of Alpha, Numeric, or * for a total of 12 characters
'WV' => ['1234567', 'E123456', 'AB123456'], # Format: 7Numeric or 1-2Alpha+5-6Numeric
'WI' => ['W1234567890123'], # Format: 1Alpha+13Numeric
Expand Down