Observable implementation of validation pattern
- 📦 NuGet:
dotnet add package ZOOMValidation
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 ...));
To validate your rules simply await .Validate()
:
bool isValid = await password.Validate();