Demos About Radzen
Search Results for

    Show / Hide Table of Contents

    Class RadzenCustomValidator

    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<TItem>. 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
    IDisposable
    IRadzenFormValidator
    Inherited Members
    ValidatorBase.messages
    ValidatorBase.SetParametersAsync(ParameterView)
    ValidatorBase.GetComponentCssClass()
    ValidatorBase.Dispose()
    ValidatorBase.BuildRenderTree(RenderTreeBuilder)
    ValidatorBase.Form
    ValidatorBase.Component
    ValidatorBase.Popup
    ValidatorBase.IsValid
    ValidatorBase.EditContext
    RadzenComponent.OnMouseEnter()
    RadzenComponent.OnMouseLeave()
    RadzenComponent.OnContextMenu(MouseEventArgs)
    RadzenComponent.GetCssClass()
    RadzenComponent.GetId()
    RadzenComponent.Debounce(Func<Task>, int)
    RadzenComponent.OnInitialized()
    RadzenComponent.OnAfterRenderAsync(bool)
    RadzenComponent.RaiseContextMenu(MouseEventArgs)
    RadzenComponent.RaiseMouseEnter()
    RadzenComponent.AddContextMenu()
    RadzenComponent.RaiseMouseLeave()
    RadzenComponent.Attributes
    RadzenComponent.Element
    RadzenComponent.MouseEnter
    RadzenComponent.MouseLeave
    RadzenComponent.ContextMenu
    RadzenComponent.Culture
    RadzenComponent.DefaultCulture
    RadzenComponent.Style
    RadzenComponent.Visible
    RadzenComponent.UniqueID
    RadzenComponent.JSRuntime
    RadzenComponent.IsJSRuntimeAvailable
    RadzenComponent.Reference
    RadzenComponent.CurrentStyle
    ComponentBase.OnInitializedAsync()
    ComponentBase.OnParametersSet()
    ComponentBase.OnParametersSetAsync()
    ComponentBase.StateHasChanged()
    ComponentBase.ShouldRender()
    ComponentBase.OnAfterRender(bool)
    ComponentBase.InvokeAsync(Action)
    ComponentBase.InvokeAsync(Func<Task>)
    ComponentBase.DispatchExceptionAsync(Exception)
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: Radzen.Blazor
    Assembly: Radzen.Blazor.dll
    Syntax
    public class RadzenCustomValidator : ValidatorBase, IComponent, IHandleEvent, IHandleAfterRender, IDisposable, 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

    RadzenCustomValidator()

    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<TItem>. 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()
    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" />

    Properties

    Text

    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
    [Parameter]
    public override string Text { get; set; }
    Property Value
    Type Description
    string

    The validation error message. Default is "Value should match".

    Overrides
    ValidatorBase.Text

    Validator

    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
    [Parameter]
    public Func<bool> Validator { get; set; }
    Property Value
    Type Description
    Func<bool>

    The validation function. Default returns true (always valid).

    Methods

    Validate(IRadzenFormComponent)

    Runs validation against the specified component.

    Declaration
    protected override bool Validate(IRadzenFormComponent component)
    Parameters
    Type Name Description
    IRadzenFormComponent component

    The component to validate.

    Returns
    Type Description
    bool

    true if validation is successful, false otherwise.

    Overrides
    ValidatorBase.Validate(IRadzenFormComponent)

    Implements

    IComponent
    IHandleEvent
    IHandleAfterRender
    IDisposable
    IRadzenFormValidator

    Introducing Radzen Blazor Studio

    Radzen Blazor Studio is a software development environment that empowers developers to design, build and deploy Blazor applications without the traditional hurdles. Write less code and get more done.

    Learn More

    Download Now
    Download Now
    In This Article
    Back to top Radzen Blazor Components, © 2018-2025 Radzen. Source Code licensed under MIT