Home

Awesome

<img src="https://raw.githubusercontent.com/JeremySkinner/FluentValidation/master/docs/assets/images/logo/fluent-validation-logo.png" alt="FluentValidation" width="250px" />

This is Fork of original FluentValidation with support .NET 3.5 Framework

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

For ASP.NET Core integration:

Install-Package FluentValidation.AspNetCore.NET35

For legacy ASP.NET MVC/WebApi integration:

Install-Package FluentValidation.MVC5.NET35
Install-Package FluentValidation.WebApi.NET35

Build Status

FluentValidationNuGetNuget
FluentValidation.AspNetCoreNuGetNuget
FluentValidation.Mvc5NuGetNuget
FluentValidation.WebApiNuGetNuget

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.