FluentValidation 12.0.0-preview1

Prefix Reserved
This is a prerelease version of FluentValidation.
dotnet add package FluentValidation --version 12.0.0-preview1                
NuGet\Install-Package FluentValidation -Version 12.0.0-preview1                
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="FluentValidation" Version="12.0.0-preview1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FluentValidation --version 12.0.0-preview1                
#r "nuget: FluentValidation, 12.0.0-preview1"                
#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.
// Install FluentValidation as a Cake Addin
#addin nuget:?package=FluentValidation&version=12.0.0-preview1&prerelease

// Install FluentValidation as a Cake Tool
#tool nuget:?package=FluentValidation&version=12.0.0-preview1&prerelease                

FluentValidation is validation library for .NET that uses a fluent interface and lambda expressions for building strongly-typed validation rules.

Supporting the project

If you use FluentValidation in a commercial project, please sponsor the project financially. FluentValidation is developed and supported by @JeremySkinner for free in his spare time and financial sponsorship helps keep the project going. You can sponsor the project via either GitHub sponsors or OpenCollective.

Example

With FluentValidation, you can define a class that inherits from AbstractValidator which contains the rules for a particular class. The example below shows how you could define rules for a Customer class, and then how to execute the validator.

using FluentValidation;

public class CustomerValidator: AbstractValidator<Customer> {
  public CustomerValidator() {
    RuleFor(x => x.Surname).NotEmpty();
    RuleFor(x => x.Forename).NotEmpty().WithMessage("Please specify a first name");
    RuleFor(x => x.Discount).NotEqual(0).When(x => x.HasDiscount);
    RuleFor(x => x.Address).Length(20, 250);
    RuleFor(x => x.Postcode).Must(BeAValidPostcode).WithMessage("Please specify a valid postcode");
  }

  private bool BeAValidPostcode(string postcode) {
    // custom postcode validating logic goes here
  }
}

var customer = new Customer();
var validator = new CustomerValidator();

// Execute the validator.
ValidationResult results = validator.Validate(customer);

// Inspect any validation failures.
bool success = results.IsValid;
List<ValidationFailure> failures = results.Errors;

Full Documentation

Full documentation can be found at https://docs.fluentvalidation.net

Release Notes and Change Log

Release notes can be found on GitHub.

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

    • No dependencies.

NuGet packages (2.4K)

Showing the top 5 NuGet packages that depend on FluentValidation:

Package Downloads
FluentValidation.DependencyInjectionExtensions

Dependency injection extensions for FluentValidation

FluentValidation.AspNetCore

AspNetCore integration for FluentValidation

MicroElements.Swashbuckle.FluentValidation

Swagger ISchemaFilter that uses FluentValidation validators instead System.ComponentModel based attributes.

Ocelot

Ocelot is an API gateway based on .NET stack.

Reo.Core.Validation

Package Description

GitHub repositories (231)

Showing the top 5 popular GitHub repositories that depend on FluentValidation:

Repository Stars
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
aspnetboilerplate/aspnetboilerplate
ASP.NET Boilerplate - Web Application Framework
kgrzybek/modular-monolith-with-ddd
Full Modular Monolith application with Domain-Driven Design approach.
Sonarr/Sonarr
Smart PVR for newsgroup and bittorrent users.
Radarr/Radarr
Movie organizer/manager for usenet and torrent users.
Version Downloads Last updated
12.0.0-preview1 19,204 1/2/2025
11.11.0 6,455,598 11/16/2024
11.10.0 9,341,108 9/15/2024
11.9.2 16,115,565 6/10/2024
11.9.1 8,800,906 4/23/2024
11.9.0 23,857,062 12/21/2023
11.8.1 6,553,010 11/22/2023
11.8.0 7,457,008 10/19/2023
11.7.1 9,727,066 8/12/2023
11.7.0 110,841 8/11/2023
11.6.0 7,425,432 7/4/2023
11.5.2 16,573,166 4/7/2023
11.5.1 43,226,654 2/20/2023
11.5.0 2,286,461 2/13/2023
11.4.0 17,029,944 11/23/2022
11.3.0 3,201,531 11/10/2022
11.2.2 14,680,576 9/11/2022
11.2.1 20,960,100 8/28/2022
11.2.0 7,150,312 8/8/2022
11.1.1 596,638 8/6/2022
11.1.0 12,028,088 6/22/2022
11.0.3 3,224,004 6/10/2022
11.0.2 4,718,892 5/27/2022
11.0.1 6,194,571 5/7/2022
11.0.0 5,253,039 4/30/2022
10.4.0 18,549,653 3/11/2022
10.3.6 25,073,283 12/13/2021
10.3.5 3,042,356 11/30/2021
10.3.4 9,566,330 10/22/2021
10.3.3 11,181,257 8/24/2021
10.3.1 693,800 8/19/2021
10.3.0 7,904,983 7/9/2021
10.2.3 7,855,750 6/3/2021
10.2.2 436,714 6/1/2021
10.2.1 1,306,995 5/30/2021
10.2.0 359,924 5/28/2021
10.1.0 5,079,640 4/28/2021
10.0.4 4,046,001 4/17/2021
9.5.4 5,546,900 4/5/2021
9.5.3 3,895,546 3/15/2021
9.5.2 1,885,253 3/8/2021
9.5.1 6,503,772 2/11/2021
9.5.0 3,138,390 1/31/2021
9.4.0 2,957,192 1/14/2021
9.3.0 13,946,577 11/10/2020
9.3.0-preview3 38,274 10/19/2020
9.3.0-preview2 148,468 9/15/2020
9.3.0-preview1 13,153 8/26/2020
9.2.2 6,917,519 9/20/2020
9.2.1 28,618 9/19/2020
9.2.0 7,607,359 8/26/2020
9.1.3 1,005,560 8/19/2020
9.1.2 925,893 8/12/2020
9.1.1 656,692 8/8/2020
9.1.0 204,279 8/8/2020
9.0.1 5,234,152 7/14/2020
9.0.0-preview5 88,898 5/23/2020
9.0.0-preview4 140,605 4/22/2020
9.0.0-preview3 197,122 2/29/2020
9.0.0-preview2 32,205 2/21/2020
9.0.0-preview1 96,317 2/8/2020
8.6.3 6,721,552 8/28/2020
8.6.2 27,059,403 2/29/2020
8.6.1 12,310,137 12/28/2019
8.6.0 4,124,235 12/4/2019
8.5.1 3,726,398 11/2/2019
8.5.0 6,031,997 9/24/2019
8.5.0-preview5 68,170 9/1/2019
8.5.0-preview4 96,401 7/23/2019
8.5.0-preview3 31,606 7/10/2019
8.5.0-preview2 80,521 6/13/2019
8.5.0-preview1 59,889 5/10/2019
8.4.0 13,899,289 5/10/2019
8.3.0 3,913,617 4/24/2019
8.2.3 675,483 4/12/2019
8.2.2 1,017,745 4/5/2019
8.2.1 467,859 4/4/2019
8.2.0 1,050,271 3/26/2019
8.1.3 5,046,997 1/25/2019
8.1.2 2,307,895 12/18/2018
8.1.1 587,361 12/11/2018
8.1.0 708,582 12/6/2018
8.1.0-preview2 29,189 11/14/2018
8.1.0-preview1 27,628 10/14/2018
8.0.101 872,233 11/24/2018
8.0.100 3,869,588 9/4/2018
8.0.0 1,074,960 8/16/2018
8.0.0-rc1 53,121 7/24/2018
8.0.0-preview4 25,614 7/16/2018
8.0.0-preview3 24,118 7/13/2018
8.0.0-preview2 23,899 7/13/2018
7.6.105 1,639,769 8/11/2018
7.6.104 2,731,122 7/6/2018
7.6.103 1,271,954 6/16/2018
7.6.102 325,191 6/14/2018
7.6.101 76,104 6/13/2018
7.6.100 173,213 6/7/2018
7.6.0 392,662 6/1/2018
7.6.0-preview1 49,656 4/12/2018
7.5.2 3,799,715 3/16/2018
7.5.1 265,089 3/11/2018
7.5.0 740,107 2/26/2018
7.4.0 1,989,852 1/26/2018
7.3.4 1,057,945 1/2/2018
7.3.3 185,763 12/22/2017
7.3.2 72,460 12/21/2017
7.3.1 331,319 12/13/2017
7.3.0 108,790 12/13/2017
7.3.0-beta3 27,989 12/8/2017
7.3.0-beta2 46,072 11/20/2017
7.3.0-beta1 24,953 11/11/2017
7.2.1 2,794,772 10/24/2017
7.2.0 810,574 10/5/2017
7.2.0-beta3 41,346 9/5/2017
7.2.0-beta2 27,132 8/22/2017
7.2.0-beta1 23,396 8/19/2017
7.1.1 2,076,188 7/25/2017
7.1.0 546,547 6/28/2017
7.1.0-beta1 23,145 6/24/2017
7.0.3 743,185 6/7/2017
7.0.2 281,161 5/26/2017
7.0.1 85,968 5/23/2017
7.0.0 669,546 5/19/2017
7.0.0-beta3 27,750 5/1/2017
7.0.0-beta2 26,819 4/17/2017
7.0.0-beta1 24,377 4/7/2017
6.4.1 1,834,345 3/15/2017
6.4.1-beta1 23,510 3/13/2017
6.4.0 927,278 3/3/2017
6.4.0-rc4 146,096 2/13/2017
6.4.0-rc3 39,198 2/3/2017
6.4.0-rc2 39,490 1/30/2017
6.4.0-rc1 23,280 1/30/2017
6.4.0-beta9 90,769 11/21/2016
6.4.0-beta8 50,291 10/31/2016
6.4.0-beta7 23,909 10/28/2016
6.4.0-beta6 24,243 10/25/2016
6.4.0-beta5 23,821 10/24/2016
6.4.0-beta4 23,935 10/21/2016
6.4.0-beta3 70,817 7/4/2016
6.4.0-beta2 24,804 7/1/2016
6.4.0-beta10 23,015 1/30/2017
6.4.0-beta1 28,112 6/28/2016
6.3.4-alpha 410,621 6/1/2016
6.3.3-alpha 22,834 5/27/2016
6.2.1 5,098,237 2/26/2016
6.2.1-beta1 28,245 2/24/2016
6.2.0 163,371 2/22/2016
6.2.0-beta1 24,097 2/12/2016
6.1.0 409,740 1/18/2016
6.0.2 113,905 1/5/2016
6.0.1 38,981 1/5/2016
6.0.0 127,144 12/22/2015
5.6.2 1,499,914 5/29/2015
5.6.1 33,960 5/29/2015
5.5.0 1,166,960 10/31/2014
5.4.0 594,206 7/3/2014
5.3.0 103,219 5/27/2014
5.2.0 74,869 5/21/2014
5.1.0 991,135 3/11/2014
5.0.0.1 503,692 10/24/2013
4.0.0.1 290,408 7/18/2013
4.0.0 115,223 4/29/2013
3.4.6 400,574 8/30/2012
3.4.0 67,598 8/17/2012
3.3.1 86,259 3/30/2012
3.2.0 73,368 11/14/2011
3.1.0 52,494 7/30/2011
3.0.0.1 25,979 7/5/2011
3.0.0 44,521 6/25/2011
2.0.0 73,131 1/9/2011
1.3.0 274,938 1/7/2011

FluentValidation 12 is a major release. Please read the upgrade guide at https://docs.fluentvalidation.net/en/latest/upgrading-to-12.html

Full release notes can be found at https://github.com/FluentValidation/FluentValidation/releases