WilvanBil.NationalRegisterNumber 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package WilvanBil.NationalRegisterNumber --version 2.1.0                
NuGet\Install-Package WilvanBil.NationalRegisterNumber -Version 2.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WilvanBil.NationalRegisterNumber" Version="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WilvanBil.NationalRegisterNumber --version 2.1.0                
#r "nuget: WilvanBil.NationalRegisterNumber, 2.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WilvanBil.NationalRegisterNumber as a Cake Addin
#addin nuget:?package=WilvanBil.NationalRegisterNumber&version=2.1.0

// Install WilvanBil.NationalRegisterNumber as a Cake Tool
#tool nuget:?package=WilvanBil.NationalRegisterNumber&version=2.1.0                

National Register Number

National Register Number is a .NET package for generating and validating Belgian national register numbers. The logic is based on the Official Documentation by the Belgian Government.


Features

  • Validation: Verify if a given national register number is valid.
  • Generation: Generate valid national register numbers with flexible parameters such as birth date and biological sex.
  • Formatting: Can format a string to YY.MM.DD-XXX.CC format using ToFormattedNationalRegisterNumber() string extension method.

Installation

Add the package to your project via the .NET CLI:

dotnet add package WilvanBil.NationalRegisterNumber

Alternatively, find it on NuGet Package Manager by searching for WilvanBil.NationalRegisterNumber.


Usage

After installation, use the static class NationalRegisterNumberGenerator to generate or validate national register numbers.

Validation

The IsValid method checks whether a given national register number is valid and returns a boolean (true/false).

bool isValid = NationalRegisterNumberGenerator.IsValid("90022742191");

Generation

The Generate method creates valid national register numbers. The following overloads are available:

string number = NationalRegisterNumberGenerator.Generate();
string number = NationalRegisterNumberGenerator.Generate(DateOnly birthDate);
string number = NationalRegisterNumberGenerator.Generate(BiologicalSex sex);
string number = NationalRegisterNumberGenerator.Generate(DateOnly birthDate, BiologicalSex sex);
string number = NationalRegisterNumberGenerator.Generate(DateOnly minDate, DateOnly maxDate);
string number = NationalRegisterNumberGenerator.Generate(DateOnly minDate, DateOnly maxDate, BiologicalSex sex);
string number = NationalRegisterNumberGenerator.Generate(DateOnly birthDate, int followNumber);

Formatting

You can format Belgian National Register Numbers into the official format (YY.MM.DD-XXX.CC) using the ToFormattedNationalRegisterNumber string extension method.

using WilvanBil.NationalRegisterNumber;

class Program
{
    static void Main(string[] args)
    {
        string nationalRegisterNumber = "90020200395";
        string formattedNumber = nationalRegisterNumber.ToFormattedNationalRegisterNumber();

        Console.WriteLine(formattedNumber); // Output: 90.02.02-003.95
    }
}

Notes:

  • Input Validation: The method will return the original string if:
    • The input is null, empty, or not exactly 11 characters.
    • You can combine this with the IsValid method from NationalRegisterNumberGenerator for additional validation.
  • Flexible Usage: Works seamlessly with any string containing a valid Belgian National Register Number.
Parameters
  • followNumber: A number between 1 and 998 (inclusive). This parameter helps ensure uniqueness when generating numbers for the same date.
  • minDate must be greater than or equal to 1900/01/01.
Exceptions

If the input parameters are invalid, the following exceptions may be thrown:

  • ArgumentException: Indicates an invalid parameter with an explanatory message.

Example Usage

Validate a National Register Number

bool isValid = NationalRegisterNumberGenerator.IsValid("90022742191");
Console.WriteLine($"Is valid: {isValid}");

Generate a Random National Register Number

string randomNumber = NationalRegisterNumberGenerator.Generate();
Console.WriteLine($"Generated number: {randomNumber}");

Generate with Specific Parameters

string numberByDate = NationalRegisterNumberGenerator.Generate(new DateOnly(1990, 1, 1));
string numberBySex = NationalRegisterNumberGenerator.Generate(BiologicalSex.Male);
string numberByDateAndSex = NationalRegisterNumberGenerator.Generate(new DateOnly(1990, 1, 1), BiologicalSex.Female);

Contributing

We welcome contributions to this package! To get started:

  1. Fork the repository: WilvanBil/NationalRegisterNumber.
  2. Clone your fork:
    git clone https://github.com/YourUsername/NationalRegisterNumber.git
    
  3. Create a new branch for your feature or bug fix:
    git checkout -b feature/my-new-feature
    
  4. Make your changes and ensure all tests pass.
  5. Submit a pull request with a clear description of your changes.

Running Tests

Before submitting your changes, run the test suite:

dotnet test

!! WARNING !!

This package is intended for testing and research purposes only. Do not use it in a live or production environment. It is specifically designed for unit and integration testing scenarios.


License

This project is licensed under the MIT License. See the LICENSE file for more details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.0 45 1/29/2025
2.2.0 51 1/24/2025
2.1.1 67 1/22/2025
2.1.0 86 1/22/2025
2.0.1 75 1/22/2025
2.0.0 75 1/22/2025
1.0.1 447 9/19/2022
1.0.0 442 9/14/2022