FluentValidation 11.9.1

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.

Showing the top 20 packages that depend on FluentValidation.

Packages Downloads
SharpGrip.FluentValidation.AutoValidation.Shared
SharpGrip FluentValidation AutoValidation is an extension of the FluentValidation library enabling automatic asynchronous validation in MVC controllers and minimal APIs (endpoints).
130
CH.DTO
Package Description
110
FluentValidation.DependencyInjectionExtensions
Dependency injection extensions for FluentValidation
90
CH.DTO
Package Description
52
CH.DTO
Package Description
48
CH.DTO
Package Description
44
CH.DTO
Package Description
43
CH.DTO
Package Description
39
CH.DTO
Package Description
32
CH.DTO
Package Description
25
CH.DTO
Package Description
22
CH.DTO
Package Description
21
CH.DTO
Package Description
20
CH.DTO
Package Description
19
CH.DTO
Package Description
18
CH.DTO
Package Description
17
CH.DTO
Package Description
16
CH.DTO
Package Description
15

FluentValidation 11 is a major release. Please read the upgrade guide at https://docs.fluentvalidation.net/en/latest/upgrading-to-11.html Full release notes can be found at https://github.com/FluentValidation/FluentValidation/releases

.NET 5.0

  • No dependencies.

.NET 6.0

  • No dependencies.

.NET 7.0

  • No dependencies.

.NET 8.0

  • No dependencies.

.NET Standard 2.0

.NET Standard 2.1

  • No dependencies.

Version Downloads Last updated
11.9.1 174 05/31/2024
11.9.0 125 05/31/2024
10.0.0 365 05/30/2024