SaudiNationalIdValidator 1.0.0
dotnet add package SaudiNationalIdValidator --version 1.0.0
NuGet\Install-Package SaudiNationalIdValidator -Version 1.0.0
<PackageReference Include="SaudiNationalIdValidator" Version="1.0.0" />
<PackageVersion Include="SaudiNationalIdValidator" Version="1.0.0" />
<PackageReference Include="SaudiNationalIdValidator" />
paket add SaudiNationalIdValidator --version 1.0.0
#r "nuget: SaudiNationalIdValidator, 1.0.0"
#:package SaudiNationalIdValidator@1.0.0
#addin nuget:?package=SaudiNationalIdValidator&version=1.0.0
#tool nuget:?package=SaudiNationalIdValidator&version=1.0.0
Saudi National ID Validator
A comprehensive .NET library for validating Saudi National IDs (including both Citizen IDs and Resident/Iqama IDs) with support for data annotations and helper methods.
Features
- ✅ Validates Saudi National ID format (10 digits)
- ✅ Verifies checksum using Luhn algorithm
- ✅ Identifies ID type (Citizen or Resident)
- ✅ Data annotation support for ASP.NET models
- ✅ Helper methods for programmatic validation
- ✅ .NET Standard 2.0 (compatible with .NET Framework 4.6.1+ and .NET Core 2.0+)
Installation
Install via NuGet Package Manager:
dotnet add package SaudiNationalIdValidator
Or via Package Manager Console:
Install-Package SaudiNationalIdValidator
Usage
1. Data Annotation (Recommended for ASP.NET Models)
Use the [SaudiNationalId] attribute to validate model properties:
using SaudiNationalIdValidator;
public class UserRegistrationModel
{
[Required]
[SaudiNationalId(ErrorMessage = "Please enter a valid Saudi National ID")]
public string NationalId { get; set; }
}
Advanced Options
Validate Citizen IDs Only:
public class CitizenModel
{
[SaudiNationalId(CitizenOnly = true)]
public string CitizenId { get; set; }
}
Validate Resident IDs Only:
public class ResidentModel
{
[SaudiNationalId(ResidentOnly = true)]
public string ResidentId { get; set; }
}
2. Helper Methods (Programmatic Validation)
Use the static helper methods for manual validation:
using SaudiNationalIdValidator;
// Simple validation (returns true/false)
string id = "1234567890";
bool isValid = ValidateSaudiNationalId.IsValid(id);
if (isValid)
{
Console.WriteLine("Valid ID");
}
else
{
Console.WriteLine("Invalid ID");
}
Get ID Type:
// Validate and get ID type
SaudiIdType idType = ValidateSaudiNationalId.Validate(id);
switch (idType)
{
case SaudiIdType.Citizen:
Console.WriteLine("Valid Saudi Citizen ID");
break;
case SaudiIdType.Resident:
Console.WriteLine("Valid Resident/Iqama ID");
break;
case SaudiIdType.Invalid:
Console.WriteLine("Invalid ID");
break;
}
Using Out Parameter:
// Validate and get ID type via out parameter
if (ValidateSaudiNationalId.Validate(id, out SaudiIdType type) != SaudiIdType.Invalid)
{
Console.WriteLine($"Valid ID of type: {type}");
}
Validation Rules
A valid Saudi National ID must:
- Be exactly 10 digits
- Start with 1 (Citizen) or 2 (Resident)
- Pass the Luhn algorithm checksum validation
Examples
1234567890- Valid if checksum passes (Citizen)2234567890- Valid if checksum passes (Resident)3234567890- Invalid (must start with 1 or 2)123456789- Invalid (must be 10 digits)12345678AB- Invalid (must be all digits)
API Reference
SaudiIdType Enum
| Value | Description |
|---|---|
Invalid |
Invalid ID or validation failed (-1) |
Citizen |
Saudi citizen ID (starts with 1) |
Resident |
Resident/Iqama ID (starts with 2) |
ValidateSaudiNationalId Class
| Method | Description |
|---|---|
IsValid(string id) |
Returns true if the ID is valid |
Validate(string id) |
Returns the SaudiIdType |
Validate(string id, out SaudiIdType idType) |
Returns the type and outputs it via parameter |
SaudiNationalIdAttribute Class
| Property | Description |
|---|---|
CitizenOnly |
Only allow citizen IDs (starting with 1) |
ResidentOnly |
Only allow resident IDs (starting with 2) |
ErrorMessage |
Custom error message |
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
| 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 was computed. 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
- System.ComponentModel.Annotations (>= 5.0.0)
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 |
|---|---|---|
| 1.0.0 | 222 | 12/25/2025 |