Skip to content

Observable implementation of validation pattern

License

Notifications You must be signed in to change notification settings

osyyyS/ZOOMValidation

Repository files navigation

ZOOMValidation

Observable implementation of validation pattern

Install

  • 📦 NuGet: dotnet add package ZOOMValidation

Usage

ValidatableObject

Add rules

You can add rules that implement IValidationRule or IAsyncValidationRule:

using ZOOMValidation;

var password = new ValidatableObject<string>();

password.ValidationRules.Add(new PasswordLengthRule("Password length must be between 12 and 24 characters", 12, 24));
password.AsyncValidationRules.Add(new PwnedPasswordRule("Password is pwned!"));

You can also add a rule without creating a class by using ValidationRule or AsyncValidationRule:

using ZOOMValidation;

var name = new ValidatableObject<string>();

name.ValidationRules.Add(new ValidationRule<string>("Name can't be empty!", name => !string.IsNullOrEmpty(name)));
name.AsyncValidationRules.Add(new AsyncValidationRule<string>("error", async name => await ...));

Validate rules

To validate your rules simply await .Validate():

bool isValid = await password.Validate();

ValidatablePair

About

Observable implementation of validation pattern

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages