RadzenRegexValidator Class

A validator component that ensures a text input matches a specified regular expression pattern. RadzenRegexValidator is useful for validating formats like ZIP codes, phone numbers, custom IDs, or any pattern-based data. Must be placed inside a RadzenTemplateForm<T>. Checks input against a regular expression pattern using .NET's RegularExpressionAttribute. Common use cases include ZIP/postal codes (e.g., "\d{5}" for US ZIP), phone numbers (e.g., "\d{3}-\d{3}-\d{4}"), custom ID formats (e.g., "^[A-Z]{2}\d{6}$"), and alphanumeric constraints (e.g., "^[a-zA-Z0-9]+$"). The validator passes when the value matches the entire pattern (implicit anchoring). Empty or null values are considered valid - combine with RadzenRequiredValidator to ensure the field is filled.

Inheritance

Object

ComponentBase

RadzenComponent

ValidatorBase

RadzenRegexValidator

Implements

IComponent

IHandleEvent

IHandleAfterRender

IRadzenFormValidator

Namespace: Radzen.Blazor

Assembly: Radzen.Blazor.dll

Syntax

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

Examples

ZIP code validation:

<RadzenTemplateForm TItem="Model" Data=@model>
    <RadzenTextBox style="display: block" Name="ZIP" @bind-Value=@model.Zip />
    <RadzenRegexValidator Component="ZIP" Pattern="^\d{5}$" Text="ZIP code must be 5 digits" Style="position: absolute" />
</RadzenTemplateForm>
@code {
    class Model { public string Zip { get; set; } }
    Model model = new Model();
}

Phone number validation:

<RadzenTextBox Name="Phone" @bind-Value=@model.Phone />
<RadzenRegexValidator Component="Phone" Pattern="^\d{3}-\d{3}-\d{4}$" Text="Format: 123-456-7890" />

Constructors

RadzenRegexValidatorlink

A validator component that ensures a text input matches a specified regular expression pattern. RadzenRegexValidator is useful for validating formats like ZIP codes, phone numbers, custom IDs, or any pattern-based data. Must be placed inside a RadzenTemplateForm<T>. Checks input against a regular expression pattern using .NET's RegularExpressionAttribute. Common use cases include ZIP/postal codes (e.g., "\d{5}" for US ZIP), phone numbers (e.g., "\d{3}-\d{3}-\d{4}"), custom ID formats (e.g., "^[A-Z]{2}\d{6}$"), and alphanumeric constraints (e.g., "^[a-zA-Z0-9]+$"). The validator passes when the value matches the entire pattern (implicit anchoring). Empty or null values are considered valid - combine with RadzenRequiredValidator to ensure the field is filled.

Declaration
public RadzenRegexValidator()

Properties

Patternlink

Gets or sets the regular expression pattern that the component value must match. Use standard .NET regex syntax. The pattern should match the entire value (implicit full-string match). Example patterns: "^\d{5}$" (5 digits), "^[A-Z]{3}\d{4}$" (3 letters + 4 digits).

Declaration
public string Pattern { get; set; }
Property Value
Type Description
stringGets or sets the regular expression pattern that the component value must match. Use standard .NET regex syntax. The pattern should match the entire value (implicit full-string match). Example patterns: "^\d{5}$" (5 digits), "^[A-Z]{3}\d{4}$" (3 letters + 4 digits).

Textlink

Gets or sets the error message displayed when the component value does not match the pattern. Customize this to provide clear guidance on the expected format.

Declaration
public string Text { get; set; }
Property Value
Type Description
stringGets or sets the error message displayed when the component value does not match the pattern. Customize this to provide clear guidance on the expected format.

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 🗙