Skip to content
Merged
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
21 changes: 21 additions & 0 deletions doc/default/id_number.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,24 @@ Faker::IdNumber.danish_id_number(gender: :female) #=> "050390-9980"
# Generate a valid French Social Security number (INSEE number)
Faker::IdNumber.french_insee_number #=> "22510589696868"
```

## ID Number and Locales

Besides the default ID numbers, faker supports localized `.valid` and `.invalid` values:

```ruby
Faker::Config.locale = 'fr-FR'
Faker::IdNumber.valid #=> "22510589696868"
```

Locales with specific intricacies are as such:

### en-GB

When the locale is set to British English, unformatted [National Insurance](https://www.gov.uk/national-insurance/your-national-insurance-number) numbers are generated:

```ruby
Faker::Config.locale = 'en-GB'
Faker::IdNumber.valid #=> "AJ405924A"
Faker::IdNumber.invalid #=> "BG316764W"

3 changes: 3 additions & 0 deletions lib/locales/en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ en-GB:
- Northern Ireland
default_country_code:
- GB
id_number:
valid: '/[A-CEGHJ-NOPR-TW-Z][ACEHJLMOPRSW][0-9]{6}[ABCD]/'
invalid: '/(BG|GB|NK|KN|TN|NT|ZZ)[0-9]{6}[E-Z]{1}/'
internet:
domain_suffix:
- co.uk
Expand Down
14 changes: 14 additions & 0 deletions test/test_en_gb_locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,18 @@ def test_en_gb_postcode_outcode_is_valid
assert_match(/^[A-PR-UWYZ][A-HK-Y0-9]/, outcode)
assert_match(/\w{1,2}\d{1,2}|\w\d[ABCDEFGHJKPSTUW]|\w\w\d[ABEHMNPRVWXY]/, outcode)
end

def test_en_gb_id_number_valid
id_code = Faker::IdNumber.valid

assert_equal(9, id_code.length)
assert_match(/^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z][0-9]{6}[A-DFM]$/, id_code)
end

def test_en_gb_id_number_invalid
id_code = Faker::IdNumber.invalid

assert_equal(9, id_code.length)
assert_not_match(/^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z][0-9]{6}[A-DFM]$/, id_code)
end
end