You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A validation library for .NET that uses a fluent interface
and lambda expressions for building strongly-typed validation rules.
Supporting the project
If you use FluentValidation in a commercial project, please sponsor the project financially. FluentValidation is developed and supported by @JeremySkinner for free in his spare time and financial sponsorship helps keep the project going. You can sponsor the project via either GitHub sponsors or OpenCollective.
Get Started
FluentValidation can be installed using the Nuget package manager or the dotnet CLI.
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();// Execute the validatorValidationResultresults=validator.Validate(customer);// Inspect any validation failures.boolsuccess=results.IsValid;List<ValidationFailure>failures=results.Errors;
License, Copyright etc
FluentValidation has adopted the Code of Conduct defined by the Contributor Covenant to clarify expected behavior in our community.
For more information see the .NET Foundation Code of Conduct.