Skip to content
A popular .NET validation for building strongly-typed validation rules.
Branch: master
Clone or download
Pull request Compare This branch is 2 commits ahead, 107 commits behind JeremySkinner:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
.nuget
docs
src
.editorconfig
.gitattributes
.gitignore
Build.cmd
Changelog.txt
FluentValidation.sln
FluentValidation.sln.DotSettings
ISSUE_TEMPLATE.md
License.txt
README.md
appveyor.yml
build.ps1
build.sh
fv-small.png
global.json

README.md

FluentValidation

Full Documentation

A small validation library for .NET that uses a fluent interface and lambda expressions for building validation rules.

Get Started

FluentValidation can be installed using the Nuget package manager or the dotnet CLI.

Install-Package FluentValidation

For ASP.NET Core integration:

Install-Package FluentValidation.AspNetCore

For legacy ASP.NET MVC/WebApi integration:

Install-Package FluentValidation.MVC5
Install-Package FluentValidation.WebApi
Build status Tests
FluentValidation NuGet Nuget
FluentValidation.AspNetCore NuGet Nuget
FluentValidation.Mvc5 NuGet Nuget
FluentValidation.WebApi NuGet Nuget

Example

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();
ValidationResult results = validator.Validate(customer);

bool success = results.IsValid;
IList<ValidationFailure> failures = results.Errors;

Documentation

Documentation can be found on the project site.

You can’t perform that action at this time.