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.
ValidatorBase.SetParametersAsync
ValidatorBase.GetComponentCssClass
RadzenComponent.OnAfterRenderAsync
RadzenComponent.RaiseContextMenu
RadzenComponent.RaiseMouseEnter
RadzenComponent.AddContextMenu
RadzenComponent.RaiseMouseLeave
RadzenComponent.OnBecameInvisible
RadzenComponent.DefaultCulture
RadzenComponent.IsJSRuntimeAvailable
ComponentBase.OnInitializedAsync
ComponentBase.OnParametersSet
ComponentBase.OnParametersSetAsync
ComponentBase.StateHasChanged
ComponentBase.ShouldRender
ComponentBase.OnAfterRender
ComponentBase.InvokeAsync
ComponentBase.DispatchExceptionAsync
ComponentBase.RendererInfo
ComponentBase.Assets
ComponentBase.AssignedRenderMode
Namespace: Radzen.Blazor
Assembly: Radzen.Blazor.dll
public class RadzenRegexValidator : ValidatorBase, IComponent, IHandleEvent, IHandleAfterRender, IRadzenFormValidatorZIP 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" />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.
public RadzenRegexValidator()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).
public string Pattern { get; set; }
| Type | Description |
|---|---|
| string | 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). |
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.
public string Text { get; set; }
| Type | Description |
|---|---|
| string | 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. |
protected override bool Validate(IRadzenFormComponent component)
| Type | Name | Description |
|---|---|---|
| IRadzenFormComponent | component |
| Type | Description |
|---|---|
| bool |