Skip to content

Commit 5fe1451

Browse files
Add GB National Insurance Numbers aka ID Numbers
In GB, we use [national insurance numbers](https://www.gov.uk/national-insurance/your-national-insurance-number) as our primary citizen identification numbers. These are 9 digit strings that are typically 2 alpha characters followed by 6 numbers and finally a single alpha. There are few combinations are not permitted [as seen here](https://www.gov.uk/hmrc-internal-manuals/national-insurance-manual/nim39110). The `valid` code provided will produce a subset of all legal NI numbers. A regex in the locale file to produce all combinations isn't necessary.
1 parent b9ef4e9 commit 5fe1451

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/locales/en-GB.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ en-GB:
8585
- Northern Ireland
8686
default_country_code:
8787
- GB
88+
id_number:
89+
valid: '/[A-CEGHJ-NOPR-TW-Z][ACEHJLMOPRSW][0-9]{6}[ABCD]/'
90+
invalid: '/(BG|GB|NK|KN|TN|NT|ZZ)[0-9]{6}[E-Z]{1}/'
8891
internet:
8992
domain_suffix:
9093
- co.uk

test/test_en_gb_locale.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,18 @@ def test_en_gb_postcode_outcode_is_valid
6969
assert_match(/^[A-PR-UWYZ][A-HK-Y0-9]/, outcode)
7070
assert_match(/\w{1,2}\d{1,2}|\w\d[ABCDEFGHJKPSTUW]|\w\w\d[ABEHMNPRVWXY]/, outcode)
7171
end
72+
73+
def test_en_gb_id_number_valid_is_valid
74+
id_code = Faker::IdNumber.valid
75+
76+
assert_equal(9, id_code.length)
77+
assert_match(/^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z][0-9]{6}[A-DFM]$/, id_code)
78+
end
79+
80+
def test_en_gb_id_number_invalid_is_invalid
81+
id_code = Faker::IdNumber.invalid
82+
83+
assert_equal(9, id_code.length)
84+
assert_not_match(/^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z][0-9]{6}[A-DFM]$/, id_code)
85+
end
7286
end

0 commit comments

Comments
 (0)