Giter Club home page Giter Club logo

fluentvalidation's Introduction

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.

dotnet add package FluentValidation

For ASP.NET Core integration:

dotnet add package FluentValidation.AspNetCore

Supporting the project

FluentValidation is developed and supported by @JeremySkinner for free in his spare time. If you find FluentValidation useful, please consider financially supporting the project via GitHub sponsors or OpenCollective which will help keep the project going ๐Ÿ™.


Build Status

FluentValidation NuGet Nuget
FluentValidation.AspNetCore NuGet Nuget
FluentValidation.Mvc5 NuGet Nuget
FluentValidation.WebApi NuGet Nuget

Example

using FluentValidation;

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
  }
}

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

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

Documentation

Documentation can be found on the project site.

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.

FluentValidation is copyright ยฉ 2008-2020 .NET Foundation, Jeremy Skinner and other contributors and is licensed under the Apache2 license.

.NET Foundation

This project is supported by the .NET Foundation.

JetBrains

This project is supported by JetBrains, who kindly provide licenses for their software, free of charge, to help with the development of this project.

fluentvalidation's People

Contributors

abatishchev avatar ademcatamak avatar avrahamcool avatar batzen avatar chris-za avatar davidjohnwilliams avatar dmorganb avatar emisand avatar filipkristo avatar gralin avatar janv8000 avatar jeremymeng avatar jeremyskinner avatar leehom0123 avatar maksimkim avatar matteobaglini avatar mattleibow avatar medvedbeast avatar mourisso avatar nsarris avatar nurulhudaapon avatar purekrome avatar richardlawley avatar robert-mccausland avatar seankilleen avatar sorenz avatar tigraine avatar utsxumiao avatar vetranio avatar wizofaus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.