RadzenCustomValidator Class

A validator component that executes custom validation logic via a user-provided function. RadzenCustomValidator enables complex validation rules that cannot be achieved with built-in validators, such as database checks, cross-field validation, or business rule enforcement. Must be placed inside a RadzenTemplateForm<T>. Provides complete flexibility for validation logic by executing a Func<bool> that you define. The validator is valid when the function returns true, invalid when it returns false. Common use cases include uniqueness checks (validating email/username against existing database records), business rules (enforcing domain-specific validation logic), cross-field validation (validating relationships between multiple fields), API validation (checking values against external services), and any complex logic requiring custom code. The Validator function should return true for valid values and false for invalid values. The function is called during form validation, so keep it fast or use async patterns for slow operations.

Inheritance

Object

ComponentBase

RadzenComponent

ValidatorBase

RadzenCustomValidator

Implements

IComponent

IHandleEvent

IHandleAfterRender

IRadzenFormValidator

Namespace: Radzen.Blazor

Assembly: Radzen.Blazor.dll

Syntax

public class RadzenCustomValidator : ValidatorBase, IComponent, IHandleEvent, IHandleAfterRender, IRadzenFormValidator

Examples

Uniqueness validation:

<RadzenTemplateForm TItem="Model" Data=@model>
    <RadzenTextBox Name="Email" @bind-Value=@model.Email />
    <RadzenCustomValidator Component="Email" Text="Email already exists" 
                           Validator=@(() => !existingEmails.Contains(model.Email)) 
                           Style="position: absolute" />
</RadzenTemplateForm>
@code {
    class Model { public string Email { get; set; } }
    Model model = new Model();
    string[] existingEmails = new[] { "user@example.com", "admin@example.com" };
}

Date range validation:

<RadzenDatePicker Name="StartDate" @bind-Value=@model.StartDate />
<RadzenDatePicker Name="EndDate" @bind-Value=@model.EndDate />
<RadzenCustomValidator Component="EndDate" Validator=@(() => model.EndDate > model.StartDate) 
                       Text="End date must be after start date" />

Constructors

RadzenCustomValidatorlink

A validator component that executes custom validation logic via a user-provided function. RadzenCustomValidator enables complex validation rules that cannot be achieved with built-in validators, such as database checks, cross-field validation, or business rule enforcement. Must be placed inside a RadzenTemplateForm<T>. Provides complete flexibility for validation logic by executing a Func<bool> that you define. The validator is valid when the function returns true, invalid when it returns false. Common use cases include uniqueness checks (validating email/username against existing database records), business rules (enforcing domain-specific validation logic), cross-field validation (validating relationships between multiple fields), API validation (checking values against external services), and any complex logic requiring custom code. The Validator function should return true for valid values and false for invalid values. The function is called during form validation, so keep it fast or use async patterns for slow operations.

Declaration
public RadzenCustomValidator()

Properties

Textlink

Gets or sets the error message displayed when the validation function returns false. Provide clear, actionable text explaining why the value is invalid and how to fix it.

Declaration
public string Text { get; set; }
Property Value
Type Description
stringGets or sets the error message displayed when the validation function returns false. Provide clear, actionable text explaining why the value is invalid and how to fix it.

Validatorlink

Gets or sets the validation function that determines whether the component value is valid. The function should return true if the value is valid, false if invalid. This function is called during form validation, so keep it fast or handle async operations appropriately.

Declaration
public Func<bool> Validator { get; set; }
Property Value
Type Description
Func<bool>Gets or sets the validation function that determines whether the component value is valid. The function should return true if the value is valid, false if invalid. This function is called during form validation, so keep it fast or handle async operations appropriately.

Methods

Validatelink

Declaration
protected override bool Validate(IRadzenFormComponent component)
Parameters
Type Name Description
IRadzenFormComponent component
Returns
Type Description
bool
An error has occurred. This app may no longer respond until reloaded. Reload 🗙