-
Notifications
You must be signed in to change notification settings - Fork 11
PropertyValidators: Messages
Vsevolod Pilipenko edited this page Jul 19, 2022
·
1 revision
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");
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.
There is possibility to use localized messages using .WithLocalizedMessage("key")
or .WithLocalizedMessage("resource", "key")
. More about this you can read here.
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);