FluentValidation

A popular .NET validation library for building strongly-typed validation rules.

  • Owner: FluentValidation/FluentValidation
  • Platform:
  • License:: Apache License 2.0
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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, -------, -----, -----, 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.

FluentValidation is copyright © 2008-2019 Jeremy Skinner and other contributors and is licensed under the Apache2 license.

Main metrics

Overview
Name With OwnerFluentValidation/FluentValidation
Primary LanguageC#
Program languagePowerShell (Language Count: 4)
Platform
License:Apache License 2.0
所有者活动
Created At2009-12-20 19:17:03
Pushed At2025-06-02 10:12:59
Last Commit At
Release Count143
Last Release Name12.0.0 (Posted on 2025-05-04 18:31:20)
First Release Name1.2rc1 (Posted on )
用户参与
Stargazers Count9.4k
Watchers Count267
Fork Count1.2k
Commits Count2.5k
Has Issues Enabled
Issues Count1785
Issue Open Count2
Pull Requests Count400
Pull Requests Open Count3
Pull Requests Close Count129
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private