All Projects → valit-stack → Valit

valit-stack / Valit

Licence: mit
Valit is dead simple validation for .NET Core. No more if-statements all around your code. Write nice and clean fluent validators instead!

Projects that are alternatives of or similar to Valit

scrupulous
Simple inline form validation using HTML5 attributes that plays nicely with Bootstrap
Stars: ✭ 12 (-96.07%)
Mutual labels:  validation
Valiktor
Valiktor is a type-safe, powerful and extensible fluent DSL to validate objects in Kotlin
Stars: ✭ 267 (-12.46%)
Mutual labels:  validation
Hamsters
A mini Scala utility library
Stars: ✭ 292 (-4.26%)
Mutual labels:  validation
Email inquire
Validate email for common typos and one-time email providers
Stars: ✭ 257 (-15.74%)
Mutual labels:  validation
Microsoft 365 Docs
This repo is used to host the source for the Microsoft 365 documentation on https://docs.microsoft.com.
Stars: ✭ 261 (-14.43%)
Mutual labels:  core
Forms
📝 Generating, validating and processing secure forms in PHP. Handy API, fully customizable, server & client side validation and mature design.
Stars: ✭ 272 (-10.82%)
Mutual labels:  validation
FluentValidation.Extensions.Br
An extension of the fluent validation with a set of Brazilian validations
Stars: ✭ 23 (-92.46%)
Mutual labels:  validation
Konform
Portable validations for Kotlin
Stars: ✭ 298 (-2.3%)
Mutual labels:  validation
Validate
Professional data validation for the R environment
Stars: ✭ 268 (-12.13%)
Mutual labels:  validation
Structure
A simple schema/attributes library built on top of modern JavaScript
Stars: ✭ 292 (-4.26%)
Mutual labels:  validation
Creditcard.js
A simple credit cards validation library in JavaScript
Stars: ✭ 259 (-15.08%)
Mutual labels:  validation
Vscode Stylelint
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 260 (-14.75%)
Mutual labels:  validation
Laravel Postal Code Validation
Worldwide postal code validation for Laravel and Lumen
Stars: ✭ 278 (-8.85%)
Mutual labels:  validation
Pt Br Validator
Uma biblioteca contendo validações de formatos Brasileiros, para o Laravel
Stars: ✭ 255 (-16.39%)
Mutual labels:  validation
Ow
Function argument validation for humans
Stars: ✭ 3,415 (+1019.67%)
Mutual labels:  validation
cli
CLI for Vela (Target's official Pipeline Automation Framework)
Stars: ✭ 23 (-92.46%)
Mutual labels:  core
Fluentresults
A generalised Result object implementation for .NET/C#
Stars: ✭ 266 (-12.79%)
Mutual labels:  validation
Check Links
Robustly checks an array of URLs for liveness. Extremely fast ⚡
Stars: ✭ 300 (-1.64%)
Mutual labels:  validation
Validate
A simple jQuery plugin to validate forms.
Stars: ✭ 298 (-2.3%)
Mutual labels:  validation
Quartzmin
Quartzmin is powerful, easy to use web management tool for Quartz.NET
Stars: ✭ 291 (-4.59%)
Mutual labels:  core

Valit

Valit is dead simple validation for .NET Core. No more if-statements all around your code. Write nice and clean fluent validators instead!

master develop
AppVeyor Build status Build status
Codecov codecov codecov

NuGet

Installation

Valit is available on NuGet.

Package manager

Install-Package Valit -Version 2.0.0

.NET CLI

dotnet add package Valit --version 2.0.0

Getting started

In order to create a validator you need to go through few steps. It's worth mentioning that not all of them are mandatory. The steps are:

  • creating new instance of validator using Create() static method.
  • choosing validation strategy using WithStrategy() method (not required).
  • selecting property using Ensure() method and defining rules for it.
  • Extending rules with custom errors (such as messages or error codes), tags and conditions. (not required).
  • applying created rules to an object using For() method.

Having the validator created, simply invoke Validate() method which will produce the result with all the data.

Let's try it out with very practical example. Imagine that your task is to validate model sent from registration page of your app. The example object might look as follows:

    public class RegisterModel
    {
        public string Email { get; set; }        
        public string Password { get; set; }
        public ushort Age { get; set ;}
    }

These are the validation criteria:

  • Email is required and needs to be a proper email address
  • Password is required and needs to be at least 10 characters long
  • Age must be greater than 16

This is how you can handle such scenario using Valit:

        void ValidateModel(RegisterModel model)
        {
            var result = ValitRules<RegisterModel>
                .Create()
                .Ensure(m => m.Email, _=>_
                    .Required()
                    .Email())
                .Ensure(m => m.Password, _=>_ 
                    .Required()
                    .MinLength(10))
                .Ensure(m => m.Age, _=>_
                    .IsGreaterThan(16))
                .For(model)
                .Validate();

            if(result.Succeeded)
            {
                // do something on success
            }
            else 
            {
                // do something on failure
            }
        }

Pretty cool, right? Of course, the above example was fairly simple but trust us. From now on, even complicated validation criterias won't scare you anymore ;)

Documentation

If you're looking for documentation, you can find it here.

Contributing

Want to help us develop Valit? Awesome! Here you can find contributor guide ;)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].