SaudiIdValidator 1.0.2
dotnet add package SaudiIdValidator --version 1.0.2
NuGet\Install-Package SaudiIdValidator -Version 1.0.2
<PackageReference Include="SaudiIdValidator" Version="1.0.2" />
<PackageVersion Include="SaudiIdValidator" Version="1.0.2" />
<PackageReference Include="SaudiIdValidator" />
paket add SaudiIdValidator --version 1.0.2
#r "nuget: SaudiIdValidator, 1.0.2"
#:package SaudiIdValidator@1.0.2
#addin nuget:?package=SaudiIdValidator&version=1.0.2
#tool nuget:?package=SaudiIdValidator&version=1.0.2
SaudiIdValidator
Validates Saudi identification numbers — National ID, Iqama and Border numbers.
Every result carries a stable code (the ID type when valid, an error code when invalid) plus a default English message, so you can show your own localized text in any language.
A number is valid when it:
- is exactly 10 digits,
- starts with
1,2,3or4, - passes the Luhn checksum.
Input is trimmed and Arabic-Indic digits (٠-٩, ۰-۹) are converted to ASCII digits before validating.
Targets netstandard2.0 and net8.0, so it works on .NET Framework 4.6.1+, .NET Core, and .NET 5+.
Install
dotnet add package SaudiIdValidator
Usage
using SaudiIdValidator;
// Quick check
bool ok = SaudiId.IsValid("1087654321");
// Full result
SaudiIdResult result = SaudiId.Validate("1087654321");
Console.WriteLine(result.IsValid); // True
Console.WriteLine(result.Code); // NationalId
Console.WriteLine(result.Message); // National ID
// Numeric input is supported too
SaudiId.IsValid(1087654321L);
Result codes
| Code | Value | Valid | Default message |
|---|---|---|---|
NationalId |
1 | ✔ | National ID |
Iqama |
2 | ✔ | Iqama ID |
BorderNumber |
3 | ✔ | Border Number (IDs starting 3 or 4) |
InvalidFormat |
101 | ✘ | ID should be 10 digits long |
InvalidPrefix |
102 | ✘ | ID should start with 1, 2, 3, or 4 |
InvalidChecksum |
103 | ✘ | ID failed Luhn algorithm |
Values below 100 are valid ID types, and values of 100 and above are errors. The numeric values are stable and will not change, so it's safe to store them or use them as keys.
Localizing messages
Map result.Code to your own text, for example with a .resx resource file or a dictionary:
var arabic = new Dictionary<SaudiIdCode, string>
{
[SaudiIdCode.NationalId] = "هوية وطنية",
[SaudiIdCode.Iqama] = "بطاقة إقامة",
[SaudiIdCode.BorderNumber] = "رقم حدود",
[SaudiIdCode.InvalidFormat] = "رقم الهوية يجب أن يتكون من 10 أرقام",
[SaudiIdCode.InvalidPrefix] = "رقم الهوية يجب أن يبدأ بـ 1، 2، 3، أو 4",
[SaudiIdCode.InvalidChecksum] = "رقم الهوية غير صحيح",
};
var result = SaudiId.Validate(input);
string text = arabic.TryGetValue(result.Code, out var t) ? t : result.Message;
SaudiId.GetDefaultMessage(code) returns the English default for any code.
SaudiIdResult
| Property | Type | Description |
|---|---|---|
IsValid |
bool |
true when all checks pass |
Id |
string |
The normalized ID that was validated |
Code |
SaudiIdCode |
ID type when valid, error code when invalid |
Message |
string |
Default English message (type name or failure reason) |
Console app
The repository includes a small console app:
# validate arguments (exit code 0 if all valid, 1 otherwise)
dotnet run --project src/SaudiIdValidator.ConsoleApp -- 1087654321 2345678904
# interactive mode
dotnet run --project src/SaudiIdValidator.ConsoleApp
Project structure
src/SaudiIdValidator/ Core library (the NuGet package)
src/SaudiIdValidator.ConsoleApp/ Console app for trying the validator
tests/SaudiIdValidator.Tests/ xUnit tests
Build & test
Requires the .NET 10 SDK.
dotnet build
dotnet test
dotnet pack src/SaudiIdValidator -c Release -o artifacts
Publishing
Pushing a tag like v1.0.0 triggers the GitHub Actions workflow in .github/workflows/publish.yml, which tests, packs and pushes the package to NuGet using Trusted Publishing, so no long-lived API key is stored. It requires a Trusted Publishing policy on nuget.org for this repository and workflow file (publish.yml), and a repository secret NUGET_USER containing the nuget.org username. The tag version overrides the <Version> in the csproj.
Contributing
Issues and pull requests are welcome at github.com/aalgrou/SaudiId-validator. Please add or update tests for any behavior change.
Author
Abdullah AlGrou — @aalgrou
License
MIT © Abdullah AlGrou
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 was computed. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net8.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.