# FluentValidation
**Repository Path**: renliguo/FluentValidation
## Basic Information
- **Project Name**: FluentValidation
- **Description**: A popular .NET validation for building strongly-typed validation rules.
- **Primary Language**: C#
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 1
- **Created**: 2019-04-09
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
[Full Documentation](https://fluentvalidation.net)
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
```
| | | |
| ------- | ----- | ----- |
| | [](https://ci.appveyor.com/project/JeremySkinner/fluentvalidation) | [](https://ci.appveyor.com/project/JeremySkinner/fluentvalidation) |
| `FluentValidation` | [](https://nuget.org/packages/FluentValidation) | [](https://nuget.org/packages/FluentValidation) |
| `FluentValidation.AspNetCore` | [](https://nuget.org/packages/FluentValidation.AspNetCore) | [](https://nuget.org/packages/FluentValidation.AspNetCore)
| `FluentValidation.Mvc5` | [](https://nuget.org/packages/FluentValidation.Mvc5) | [](https://nuget.org/packages/FluentValidation.Mvc5)
| `FluentValidation.WebApi` | [](https://nuget.org/packages/FluentValidation.WebApi) | [](https://nuget.org/packages/FluentValidation.WebApi)
### Example
```csharp
using FluentValidation;
public class CustomerValidator: AbstractValidator {
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 failures = results.Errors;
```
### Documentation
[Documentation can be found on the project site.](https://fluentvalidation.net)