Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
101 lines (75 sloc) 2.03 KB

FluentValidation

FluentValidation is a A .NET library for building strongly-typed validation rules.

The following platforms are supported:

For automatic validation with ASP.NET, FluentValidation supports ASP.NET Core 2.1+ (3.1 recommended)

If you're new to using FluentValidation, check out the :doc:`start` page.

Example

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
  }
}
.. toctree::
  :maxdepth: 1
  :caption: Getting Started

  installation
  start
  collections
  rulesets
  including-rules
  upgrading-to-9
  upgrading-to-8

.. toctree::
  :maxdepth: 1
  :caption: Configuring Validators

  configuring
  conditions


.. toctree::
  :maxdepth: 1
  :caption: Building Rules

  built-in-validators
  custom-validators

.. toctree::
  :maxdepth: 1
  :caption: Localization

  localization

.. toctree::
  :maxdepth: 1
  :caption: Testing

  testing

.. toctree::
  :maxdepth: 1
  :caption: ASP.NET Integration

  aspnet
  mvc5
  webapi

.. toctree::
  :maxdepth: 1
  :caption: Advanced

  async
  transform
  advanced
You can’t perform that action at this time.