Class RadzenRegexValidator
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<TItem>. 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.
Inherited Members
Namespace: Radzen.Blazor
Assembly: Radzen.Blazor.dll
Syntax
public class RadzenRegexValidator : ValidatorBase, IComponent, IHandleEvent, IHandleAfterRender, IDisposable, 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
RadzenRegexValidator()
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<TItem>. 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()
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" />
Properties
Pattern
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
[Parameter]
public string Pattern { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The regex pattern string. |
Text
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
[Parameter]
public override string Text { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The validation error message. Default is "Value should match". |
Overrides
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 |
|