Skip to content

PropertyValidators: Messages

Vsevolod Pilipenko edited this page Jul 19, 2022 · 1 revision

How to use

The library contains default messages for validators, but you can specify another when create rules:

builder.RuleFor(vm => vm.Password)
    .NotEmpty()
    .MinLength(8, ValidationMessageType.Warning)
        .WithMessage("Your password is not secure");

Parameters

Some of validators also provide special parameters which you can use in your messages.

builder.RuleFor(vm => vm.Password)
    .NotEmpty()
    .MinLength(8, ValidationMessageType.Warning)
        .WithMessage("For a secure password, enter more than {MinLength} characters. You entered {TotalLength} characters");

Which parameters uses for each validator you can find in file with default messages.

Localization

There is possibility to use localized messages using .WithLocalizedMessage("key") or .WithLocalizedMessage("resource", "key"). More about this you can read here.

Create custom string source

If you need, you can create custom string source using interface ReactiveValidation.Resources.StringSources.IStringSource and use it like that:

builder.RuleFor(vm => vm.Password)
    .NotEmpty()
    .MinLength(8, ValidationMessageType.Warning)
        .WithMessageSource(new YourMessageSource);