FluentValidation

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

  • 所有者: FluentValidation/FluentValidation
  • 平台:
  • 许可证: Apache License 2.0
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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.

主要指标

概览
名称与所有者FluentValidation/FluentValidation
主编程语言C#
编程语言PowerShell (语言数: 4)
平台
许可证Apache License 2.0
所有者活动
创建于2009-12-20 19:17:03
推送于2025-06-02 10:12:59
最后一次提交
发布数143
最新版本名称12.0.0 (发布于 2025-05-04 18:31:20)
第一版名称1.2rc1 (发布于 )
用户参与
星数9.4k
关注者数267
派生数1.2k
提交数2.5k
已启用问题?
问题数1785
打开的问题数2
拉请求数400
打开的拉请求数3
关闭的拉请求数129
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?