Olve.Validation 0.38.0

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

Olve.Validation

NuGet Docs

Fluent validation helpers built on top of Olve.Results. Validators accumulate rules and return a Result containing all problems found.


Installation

dotnet add package Olve.Validation

Overview

Type Description
StringValidator String validation: null checks, length constraints, allowed/disallowed values.
IntValidator Integer validation: numeric range, even/odd.
DecimalValidator<T> Generic numeric validation for any INumber<T> type.
EnumerableValidator<T> Collection validation: empty, duplicates, count.
ListValidator<T> Optimized collection validation for IList<T>.
IValidator<T> Interface for any validator that returns Result.
IValidatable Interface for objects that can validate their own state.

Usage

String validation

Chain rules to build a validator, then call Validate() to get a Result.

// ../../tests/Olve.Validation.Tests/ReadmeDemo.cs#L12-L16

var result = new StringValidator()
    .CannotBeNullOrWhiteSpace()
    .MustHaveMinLength(3)
    .MustHaveMaxLength(50)
    .Validate("Alice");

When multiple rules fail, all problems are collected into the result:

// ../../tests/Olve.Validation.Tests/ReadmeDemo.cs#L24-L34

var result = new StringValidator()
    .CannotBeNullOrWhiteSpace()
    .MustHaveMinLength(3)
    .Validate("");

// Multiple rules can fail at once — all problems are collected
if (result.TryPickProblems(out var problems))
{
    foreach (var p in problems)
        Console.WriteLine(p.Message);
}

Numeric validation

IntValidator provides integer-specific rules like MustBeEven() and MustBeOdd() on top of the standard numeric range methods.

// ../../tests/Olve.Validation.Tests/ReadmeDemo.cs#L43-L46

var result = new IntValidator()
    .MustBePositive()
    .MustBeLessThan(100)
    .Validate(42);

DecimalValidator<T> works with any INumber<T> type (double, decimal, float, etc.):

// ../../tests/Olve.Validation.Tests/ReadmeDemo.cs#L54-L56

var result = new DecimalValidator<double>()
    .MustBeBetween(0.0, 1.0)
    .Validate(0.5);

Collection validation

// ../../tests/Olve.Validation.Tests/ReadmeDemo.cs#L64-L68

var result = new EnumerableValidator<string>()
    .CannotBeNull()
    .CannotBeEmpty()
    .CannotContainDuplicates()
    .Validate(new[] { "a", "b", "c" });

ListValidator<T> provides the same API optimized for IList<T>.


Custom error messages

Use WithMessage() or WithProblem() after a rule to override its default error:

// ../../tests/Olve.Validation.Tests/ReadmeDemo.cs#L76-L87

var result = new StringValidator()
    .CannotBeNullOrWhiteSpace()
    .WithMessage("Username is required")
    .MustHaveMinLength(3)
    .WithMessage("Username must be at least 3 characters")
    .Validate(null);

if (result.TryPickProblems(out var problems))
{
    foreach (var p in problems)
        Console.WriteLine(p.Message);
}

Integration with Olve.Results

Validators return Result, so they compose naturally with the rest of the Olve.Results API:

// ../../tests/Olve.Validation.Tests/ReadmeDemo.cs#L95-L104

Result ValidateEmail(string? email)
{
    return new StringValidator()
        .CannotBeNullOrWhiteSpace()
        .WithMessage("Email is required")
        .Validate(email);
}

var valid = ValidateEmail("user@example.com");
var invalid = ValidateEmail(null);

Documentation

Full API reference: https://olivervea.github.io/Olve.Utilities/api/Olve.Validation.html


License

MIT License © OliverVea

Product Compatible and additional computed target framework versions.
.NET 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.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Olve.Validation:

Package Downloads
Olve.Utilities

Various pieces of utility

Olve.MinimalApi

Minimal API extensions for ASP.NET Core including JSON conversion for IPath, result mapping, and validation helpers

Olve.Logging

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.38.0 298 2/19/2026
0.37.2 113 2/18/2026
0.37.1 104 2/18/2026
0.37.0 110 2/17/2026
0.36.1 398 11/15/2025
0.36.0 206 11/15/2025
0.35.2 195 11/9/2025
0.35.1 172 11/8/2025
0.35.0 167 11/8/2025
0.34.0 164 10/4/2025
0.33.0 153 9/13/2025
0.32.2 219 8/9/2025
0.32.1 209 8/9/2025
0.32.0 253 8/8/2025
0.31.0 334 8/5/2025
0.30.0 143 8/3/2025
0.29.1 128 8/3/2025
0.29.0 132 8/3/2025
0.28.2 112 8/2/2025