TurkishValidators.FluentValidation 1.1.0

dotnet add package TurkishValidators.FluentValidation --version 1.1.0
                    
NuGet\Install-Package TurkishValidators.FluentValidation -Version 1.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="TurkishValidators.FluentValidation" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TurkishValidators.FluentValidation" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="TurkishValidators.FluentValidation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TurkishValidators.FluentValidation --version 1.1.0
                    
#r "nuget: TurkishValidators.FluentValidation, 1.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.
#:package TurkishValidators.FluentValidation@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TurkishValidators.FluentValidation&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=TurkishValidators.FluentValidation&version=1.1.0
                    
Install as a Cake Tool

TurkishValidators 🇹🇷

<img src="icon.png" align="right" width="128" height="128" />

.NET License: MIT NuGet

TurkishValidators, Türkiye'ye özgü veri tipleri (TCKN, Vergi No, IBAN, Telefon, Plaka, Posta Kodu) için geliştirilmiş; performanslı, hafif, API bağımlılığı olmayan ve genişletilebilir bir .NET doğrulama kütüphanesidir.

🚀 Özellikler

  • Tamamen Offline: Hiçbir dış servise veya API'ye istek atmaz. Matematiksel algoritmalarla çalışır.
  • Yüksek Performans: Allocation-free (tahsisatsız) algoritmalar ve optimize edilmiş string işlemleri.
  • Geniş Kapsam:
    • TC Kimlik Numarası (Algoritma + Test Numarası Desteği)
    • Vergi Kimlik Numarası (VKN)
    • IBAN (TR IBAN Formatı + Checksum)
    • Telefon Numarası (GSM ve Sabit Hat, Operör Kontrolü)
    • Araç Plakası (81 İl Kodu, Resmi/Özel Plaka Formatları)
    • Posta Kodu (81 İl ve İlçe Validasyonu)
  • Çoklu Dil Desteği (Localization): Türkçe (Varsayılan) ve İngilizce hata mesajları.
  • Veri Maskeleme: KVKK/GDPR uyumlu veri maskeleme yardımcıları.
  • Entegrasyonlar:
    • ASPNET Core ValidationAttribute desteği.
    • FluentValidation extension metodları.
  • Test Verisi Üretimi: Testleriniz için geçerli rastgele veri üreten TurkishValidators.TestData paketi.

📦 Kurulum

Projenize NuGet üzerinden ekleyebilirsiniz:

# Core Kütüphane (Temel Doğrulayıcılar)
dotnet add package TurkishValidators

# ASP.NET Core Entegrasyonu (Attributes)
dotnet add package TurkishValidators.AspNetCore

# FluentValidation Entegrasyonu
dotnet add package TurkishValidators.FluentValidation

# Test Verisi Üreticisi (Test Projeleri İçin)
dotnet add package TurkishValidators.TestData

# System.Text.Json Entegrasyonu
dotnet add package TurkishValidators.Json

💻 Kullanım

1. Temel Kullanım (Core)

using TurkishValidators.Validators;

// TC Kimlik No Doğrulama
var tcknValidator = new TcKimlikNoValidator();
var result = tcknValidator.Validate("10000000146");
if (result.IsValid)
{
    Console.WriteLine("Geçerli TCKN!");
}
else
{
    Console.WriteLine(result.ErrorMessage); // "TC Kimlik Numarası geçersiz."
}

// Statik Kullanım
bool isValid = TcKimlikNoValidator.IsValid("10000000146");

2. ASP.NET Core Entegrasyonu (Attributes)

Model sınıflarınızda doğrudan kullanabilirsiniz:

using TurkishValidators.AspNetCore.Attributes;

public class UserDto
{
    [TcKimlikNo(ErrorMessage = "Lütfen geçerli bir TC giriniz.")]
    public string NationalId { get; set; }

    [TurkishPhone]
    public string PhoneNumber { get; set; }

    [VehiclePlate]
    public string CarPlate { get; set; }
}

3. FluentValidation Entegrasyonu

Mevcut validator sınıflarınızda zincirleme metodlar (chaining) ile kullanın:

using FluentValidation;
using TurkishValidators.FluentValidation.Extensions;

public class CustomerValidator : AbstractValidator<Customer>
{
    public CustomerValidator()
    {
        RuleFor(x => x.TcNo).MustBeTurkishIdentity();
        RuleFor(x => x.Iban).MustBeTurkishIban();
        RuleFor(x => x.Plate).MustBeVehiclePlate();
        
        // Opsiyonel Ayarlar
        RuleFor(x => x.TaxNo).MustBeTurkishTaxNumber(new VergiNoValidationOptions 
        { 
             // Ayarlar...
        });
    }
}

4. Veri Maskeleme (Masking)

Hassas verileri loglarken veya gösterirken maskeleyin:

using TurkishValidators.Masking;

string maskedTc = TcKimlikNoMasker.Mask("12345678901"); 
// Çıktı: 123******01 (Varsayılan: İlk 3, Son 2 açık)

string maskedIban = IbanMasker.Mask("TR330006100519786457841326");
// Çıktı: TR********************1326

// Özel Ayarlar
var options = new MaskingOptions { VisibleStart = 0, VisibleEnd = 4, MaskChar = 'X' };
string customMask = TcKimlikNoMasker.Mask("12345678901", options);
// Çıktı: XXXXXXX8901

5. Test Verisi Üretimi (TestData)

Testlerinizde kullanmak üzere geçerli rastgele veriler üretin:

using TurkishValidators.TestData.Services;

var provider = new TurkishDataProvider();

string randomTc = provider.GenerateTcKimlikNo();
string randomIban = provider.GenerateTurkishIban();
string istPlate = provider.GenerateVehiclePlate("İstanbul"); // 34 ... ...

// Toplu Veri Üretimi
var bulkData = provider.GenerateBulk(100);

// Toplu Veri Üretimi var bulkData = provider.GenerateBulk(100);


### 6. Kredi Kartı & BIN Sorgulama (Yeni!)

Luhn algoritması kontrolü ve banka BIN analizi (Troy, Visa, Mastercard tespiti):

```csharp
using TurkishValidators.Validators;
using TurkishValidators.Enums;

bool isValid = CreditCardValidator.IsValid("4543600000000003");

var result = CreditCardValidator.GetBinInfo("4543600000000003");
if (result.IsValid)
{
    Console.WriteLine($"Bank: {result.BankName}"); // Türkiye İş Bankası
    Console.WriteLine($"Type: {result.CardType}"); // Visa
}

7. System.Text.Json Entegrasyonu (Yeni!)

JSON çıktısında veriyi otomatik maskelemek için:

  1. TurkishValidators.Json paketini yükleyin.
  2. Property üzerine attribute ekleyin:
using System.Text.Json;
using System.Text.Json.Serialization;
using TurkishValidators.Json.Converters;

public class UserDto
{
    [JsonConverter(typeof(TcknMaskingConverter))]
    public string Tckn { get; set; } = "12345678901";
}

// Çıktı: {"Tckn": "123******01"}

8. TurkishFaker (Statik Test Verisi) (Yeni!)

Hızlıca mock data üretmek için statik erişim:

using TurkishValidators.TestData;

string tckn = TurkishFaker.GenerateTCKN();
string iban = TurkishFaker.GenerateIBAN();
string mobil = TurkishFaker.GenerateGSM();

⚙️ Yapılandırma (Configuration)

Uygulama genelinde hata mesajı dilini veya formatını değiştirebilirsiniz:

using TurkishValidators.Config;

// Uygulama başlangıcında (Program.cs / Startup.cs)
TurkishValidatorConfig.Culture = new System.Globalization.CultureInfo("en-US");
// Artık hata mesajları İngilizce dönecektir.

🌍 Gelişmiş Dil Desteği (Advanced Localization)

Varsayılan Türkçe ve İngilizce mesajların yanı sıra, yeni diller ekleyebilir veya mevcut mesajları ezebilirsiniz:

using TurkishValidators.Config;
using TurkishValidators.Resources;

// Almanca için özel mesaj seti tanımlama
var germanMessages = new ValidationMessages
{
    TcKimlikNoEmpty = "Die TC-Identitätsnummer darf nicht leer sein.",
    TcKimlikNoLength = "Die TC-Identitätsnummer muss 11 Ziffern lang sein.",
    // Diğer mesajlar...
};

// "de-DE" kültürü için kaydet
TurkishValidatorConfig.RegisterMessages("de-DE", germanMessages);

// Veya mevcut Türkçe mesajı değiştirme
var customTr = ValidationMessages.CreateDefault();
customTr.TcKimlikNoEmpty = "Lütfen TCKN alanını boş bırakmayınız!";
TurkishValidatorConfig.RegisterMessages("tr-TR", customTr);

🔌 Uyumluluk (Compatibility)

Proje .NET Standard 2.0 hedeflemektedir, bu sayede aşağıdaki platformların tamamında sorunsuz çalışır:

  • .NET 5, .NET 6, .NET 7, .NET 8+
  • .NET Core 2.0+
  • .NET Framework 4.6.1+

🏗️ Proje Yapısı

  • src/TurkishValidators: Çekirdek kütüphane.
  • src/TurkishValidators.AspNetCore: ASP.NET Core attribute'ları.
  • src/TurkishValidators.FluentValidation: FluentValidation eklentileri.
  • src/TurkishValidators.TestData: Test verisi üretim kütüphanesi.

🤝 Katkıda Bulunma

PR'lar kabul edilir! Lütfen önce bir issue açarak değişikliği tartışın.

📄 Lisans

Bu proje MIT lisansı ile lisanslanmıştır.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1.0 103 1/1/2026
1.0.2 90 1/1/2026
1.0.1 97 1/1/2026
1.0.0 96 1/1/2026