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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?