Skip to content

Repository files navigation

FluentValidation

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

FluentValidationNuGetNuget
FluentValidation.AspNetCoreNuGetNuget
FluentValidation.Mvc5NuGetNuget
FluentValidation.WebApiNuGetNuget

Example

usingFluentValidation;publicclassCustomerValidator:AbstractValidator<Customer>{publicCustomerValidator(){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");}privateboolBeAValidPostcode(stringpostcode){// custom postcode validating logic goes here}}varcustomer=newCustomer();varvalidator=newCustomerValidator();ValidationResultresults=validator.Validate(customer);boolsuccess=results.IsValid;IList<ValidationFailure>failures=results.Errors;

Documentation

Documentation can be found on the project site.

About

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

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages