Skip to content

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

License

Notifications You must be signed in to change notification settings

wizofaus/FluentValidation

This branch is 4 commits ahead of, 1340 commits behind FluentValidation/FluentValidation:main.

Folders and files

NameName
Last commit message
Last commit date
Aug 26, 2017
Jan 30, 2017
Nov 11, 2017
Jul 14, 2016
May 27, 2012
Jun 12, 2017
Nov 11, 2017
Nov 11, 2017
Sep 23, 2015
Aug 26, 2017
Apr 5, 2017
Apr 29, 2010
Mar 6, 2017
Jan 13, 2016
Apr 16, 2017
Dec 20, 2009

Repository files navigation

FluentValidation

Full Documentation

A small validation library for .NET that uses a fluent interface and lambda expressions for building validation rules. Written by Jeremy Skinner (http://www.jeremyskinner.co.uk) and licensed under Apache 2.

NuGet Packages

Install-Package FluentValidation

For ASP.NET MVC integration:

Install-Package FluentValidation.MVC5

For ASP.NET Core:

Install-Package FluentValidation.AspNetCore

Example

using FluentValidation;

public class CustomerValidator: AbstractValidator<Customer> {
  public CustomerValidator() {
    RuleFor(customer => customer.Surname).NotEmpty();
    RuleFor(customer => customer.Forename).NotEmpty().WithMessage("Please specify a first name");
    RuleFor(customer => customer.Discount).NotEqual(0).When(customer => customer.HasDiscount);
    RuleFor(customer => customer.Address).Length(20, 250);
    RuleFor(customer => customer.Postcode).Must(BeAValidPostcode).WithMessage("Please specify a valid postcode");
  }

  private bool BeAValidPostcode(string postcode) {
    // custom postcode validating logic goes here
  }
}

Customer customer = new Customer();
CustomerValidator validator = new CustomerValidator();
ValidationResult results = validator.Validate(customer);

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

Further Documentation

Documentation can be found here.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.5%
  • Other 0.5%