Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add en-GB ID Numbers (aka National Insurance Numbers) #3032

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stefanjcollier
Copy link

Motivation / Background

In GB, we use national insurance numbers as our primary citizen identification numbers.

Additional information

National Insurance Numbers 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.

The valid regex provided will produce a subset of all legal NI numbers. I didn't consider a regex to produce all combinations wasn't necessary.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug, refactor something, or add a feature.
  • Tests and Rubocop are passing before submitting your proposed changes.

If you're proposing a new generator or locale:

  • Double-check the existing generators documentation to make sure the new generator you want to add doesn't already exist.
  • You've reviewed and followed the Contributing guidelines.

@stefanjcollier stefanjcollier marked this pull request as ready for review December 5, 2024 18:36
@stefanjcollier stefanjcollier marked this pull request as draft December 5, 2024 18:37
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.
@stefanjcollier stefanjcollier marked this pull request as ready for review December 5, 2024 18:44
@stefanjcollier
Copy link
Author

Faker::IdNumber.valid

image

Faker::IdNumber.invalid

image

@stefanjcollier stefanjcollier changed the title Add GB National Insurance Numbers aka ID Numbers Add GB ID Numbers (aka National Insurance Numbers) Dec 5, 2024
@stefanjcollier stefanjcollier changed the title Add GB ID Numbers (aka National Insurance Numbers) Add en-GB ID Numbers (aka National Insurance Numbers) Dec 6, 2024
Copy link
Contributor

@stefannibrasil stefannibrasil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the screenshots! What do you think of adding a note in the documentation for this locale that the result will be normalized? The doc could have a section for locales: https://github.com/faker-ruby/faker/blob/main/doc/default/id_number.md?plain=1

@stefanjcollier
Copy link
Author

stefanjcollier commented Jan 8, 2025

Great shout! I've attempted to document it in the same style and writing style.
I hope this was how you were intending?

Happy to rewrite according to any examples. Feedback very welcome, I doubt you could offend me. 😄

Copy link
Contributor

@stefannibrasil stefannibrasil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @stefanjcollier I left some suggestions.

Comment on lines +55 to +56
Besides the locale-specific ID Number methods. Faker supports retrieving localised calls to `.valid` and `.invalid`.
Here is an example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Besides the locale-specific ID Number methods. Faker supports retrieving localised calls to `.valid` and `.invalid`.
Here is an example:
Besides the default ID Number methods, Faker supports localized `.valid` and `.invalid` values. Here is an example:

Comment on lines +65 to +73
### en-GB
When provided with British English, unformatted'[National Insurance](https://www.gov.uk/national-insurance/your-national-insurance-number)' numbers are generated.
Note: Faker can only generate a subset of all possible legal/illegal national insurance numbers.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### en-GB
When provided with British English, unformatted'[National Insurance](https://www.gov.uk/national-insurance/your-national-insurance-number)' numbers are generated.
Note: Faker can only generate a subset of all possible legal/illegal national insurance numbers.
```ruby
Faker::Config.locale = 'en-GB'
Faker::IdNumber.valid #=> "AJ405924A"
Faker::IdNumber.invalid #=> "BG316764W"
```
### 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"

Note: Faker generates a subset of all possible legal/illegal national insurance numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants