This repository provides tools for validating and generating Japanese My Number (Social Security and Tax Number System) in .NET 8.0.
- MyNumberNET/: Core .NET 8.0 library for My Number validation and generation.
- MyNumberNET_ApiServer/: ASP.NET Core Web API for My Number validation and generation.
- MyNumberNET_CLI/: Command-line interface for interacting with the library. Uses NLog for logging.
- MyNumberNET_Test/: Unit tests for the library and API server.
- Jenkinsfile: CI/CD pipeline configuration.
- global.json: Specifies the .NET SDK version.
- MyNumberNET.sln: Solution file for managing all projects.
A .NET 8.0 library for validating and generating My Number sequences.
Features:
- Validate a 12-digit My Number:
MyNumber.VerifyNumber(int[] number) - Calculate check digit for first 11 digits:
MyNumber.CalculateCheckDigits(int[] number) - Exception handling for malformed input
Example Usage:
using MyNumberNET;
int[] number = {6,1,4,1,0,6,5,2,6,0,0,0};
bool isValid = MyNumber.VerifyNumber(number);An immutable, strongly-typed value object that encapsulates a validated My Number. Constructing a MyNumberValue will validate format and check digit, making it safer to pass My Number values in code and APIs.
Key points:
- Immutable and validated on creation.
- Construct from
int[],string, or individual digits. TryParse/Parseavailable for safe parsing.- Provides
ToString(format)with formats:N(plain),S(spaces),H(hyphens),G(grouped).
Example usage:
using MyNumberNET;
// Parse from string
var value = MyNumberValue.Parse("614106526000");
// Safe parse
if (MyNumberValue.TryParse("6141-0652-6000", out var parsed))
{
Console.WriteLine(parsed.ToString("H")); // 6141-0652-6000
}
// Create from first 11 digits (check digit calculated)
var complete = MyNumberValue.FromFirstElevenDigits(new int[] {6,1,4,1,0,6,5,2,6,0,0});
// Generate random valid My Number
var random = MyNumberValue.GenerateRandom();
// Implicit conversions to `string` and `int[]`
string s = random; // "614106526000"
int[] digits = random;ASP.NET Core Web API for validating and generating My Numbers.
Usage:
dotnet run --project MyNumberNET_ApiServer
The API exposes endpoints for validation and generation. See Controllers/MyNumberController.cs for details.
A command-line interface for validating and generating My Numbers. Uses NLog for logging.
Usage:
dotnet run --project MyNumberNET_CLI [command] [arguments]
Or run the built executable directly:
MyNumberNET_CLI\bin\Debug\net8.0\MyNumberNET_CLI.exe [command] [arguments]
Commands:
generate [count]: Generate valid My Numberscheck [My Number]: Validate a given numbercomplete [first 11 digits]: Complete a number by calculating the check digitrangen [min] [max]: Generate numbers in a numerical rangeranges [min] [max]: Generate numbers in a sequential range
Unit tests for the library and API server.
Run tests:
dotnet test MyNumberNET_Test
Use the solution file to build and manage all projects:
dotnet build MyNumberNET.sln
This repository uses .NET 8.0. The required SDK version is specified in global.json.