SmartValidationsLibrary 2.1.0

dotnet add package SmartValidationsLibrary --version 2.1.0
                    
NuGet\Install-Package SmartValidationsLibrary -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="SmartValidationsLibrary" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SmartValidationsLibrary" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SmartValidationsLibrary" />
                    
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 SmartValidationsLibrary --version 2.1.0
                    
#r "nuget: SmartValidationsLibrary, 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.
#:package SmartValidationsLibrary@2.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=SmartValidationsLibrary&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SmartValidationsLibrary&version=2.1.0
                    
Install as a Cake Tool

Smart Validations Library

NuGet .NET License: MIT

SmartValidationsLibrary is a lightweight, non-throwing C# validation library. Every check returns a ValidationResult (IsValid + ErrorMessage) instead of an exception, and every validation also ships as an attribute so you can validate a whole object's properties in one call.

Features

  • Email — IsValidEmail / [EmailValidation]
  • Phone number, region-aware (USA, UK, Spain, Ireland) — IsValidPhoneNumber / [PhoneNumberValidation(Region.Spain)]
  • Postal code, region-aware (USA, UK, Spain, Ireland) — IsValidPostalCode / [PostalCodeValidation(Region.Spain)]
  • Date — IsValidDate
  • URL (http/https) — IsValidUrl / [UrlValidation]
  • Credit card number (Luhn checksum) — IsValidCreditCardNumber / [CreditCardValidation]
  • Password strength, configurable — IsValidPassword / [PasswordValidation]
  • IP address (IPv4/IPv6) — IsValidIPAddress / [IPAddressValidation]
  • Numeric range — IsInRange / [RangeValidation(min, max)]
  • String length — IsValidLength / [LengthValidation(min, max)]
  • Custom rules — register your own regex via AddCustomValidation, then IsValidCustom / [CustomValidation("name")]
  • Entity validation — EntityValidator.ValidateEntity<T> collects every failing property on an object, not just the first one

Installation

dotnet add package SmartValidationsLibrary

Usage

Standalone checks

using SmartValidationsLibrary;

var result = Validator.IsValidEmail("user@example.com");
if (!result.IsValid)
    Console.WriteLine(result.ErrorMessage);

Validator.IsValidPhoneNumber("612345678", Region.Spain);
Validator.IsValidPostalCode("28001", Region.Spain);
Validator.IsValidDate("2026-01-15");
Validator.IsValidUrl("https://example.com");
Validator.IsValidCreditCardNumber("4111 1111 1111 1111");
Validator.IsValidPassword("Str0ng!Pass");
Validator.IsValidIPAddress("192.168.1.1");
Validator.IsInRange(5, 1, 10);
Validator.IsValidLength("hello", 1, 10);

Validator.AddCustomValidation("digits-only", @"^\d+$");
Validator.IsValidCustom("12345", "digits-only");

Entity validation with attributes

using SmartValidationsLibrary;

public class SignupRequest
{
    [EmailValidation]
    public string Email { get; set; } = string.Empty;

    [PhoneNumberValidation(Region.Spain)]
    public string Phone { get; set; } = string.Empty;

    [PasswordValidation(minLength: 8)]
    public string Password { get; set; } = string.Empty;

    [LengthValidation(2, 50)]
    public string DisplayName { get; set; } = string.Empty;
}

var errors = EntityValidator.ValidateEntity(signupRequest);
// errors is empty when everything is valid, otherwise contains
// one ValidationResult per failing property (PropertyName + ErrorMessage).

Requirements

  • .NET 8.0, 9.0, or 10.0

Development

Want to contribute? Great!

git clone https://github.com/AdrianBailador/SmartValidationsLibrary.git
cd SmartValidationsLibrary
dotnet test

Please include tests for any new functionality.

License

MIT — see LICENSE.

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.  net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • 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.1.0 144 8/15/2026
2.0.0 117 8/15/2026
1.0.1 278 8/26/2023
1.0.0 239 8/23/2023

Now multi-targets net8.0, net9.0, and net10.0 (was net10.0-only). Same 2.0.0 rewrite otherwise: fixed IsValidEmail throwing RegexParseException on every call due to invalid character-class syntax in the email pattern, fixed two conflicting EntityValidator implementations existing side by side (consolidated into one that collects every validation error), fixed the UK phone number regex rejecting real numbers, and added IsValidPostalCode, IsValidUrl, IsValidCreditCardNumber, IsValidPassword, IsValidIPAddress, IsInRange, and IsValidLength, each with a matching validation attribute.