# 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>](https://blazor.radzen.com/docs/api/Radzen.Blazor.RadzenTemplateForm-1.md). 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.

Namespace: [Radzen.Blazor](https://blazor.radzen.com/docs/api/Radzen.Blazor.md)

Assembly: Radzen.Blazor.dll

## Inheritance

- Object
- ComponentBase
- [RadzenComponent](https://blazor.radzen.com/docs/api/Radzen.RadzenComponent.md)
- [ValidatorBase](https://blazor.radzen.com/docs/api/Radzen.Blazor.ValidatorBase.md)
- RadzenRegexValidator

## Implements

- IComponent
- IHandleEvent
- IHandleAfterRender
- [IRadzenFormValidator](https://blazor.radzen.com/docs/api/Radzen.IRadzenFormValidator.md)

## Syntax

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

## Examples

ZIP code validation:

```razor
<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:

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

## Constructors

| Constructor | Description |
|-------------|-------------|
| `public 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<T>](https://blazor.radzen.com/docs/api/Radzen.Blazor.RadzenTemplateForm-1.md). 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. |

## Properties

| Property | Type | Description |
|------|------|-------------|
| Pattern | `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). |
| Text | `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. |

## Methods

| Method | Returns | Description |
|------|---------|-------------|
| `Validate(IRadzenFormComponent component)` | `bool` |  |

## Inherited Members

- From [ValidatorBase](https://blazor.radzen.com/docs/api/Radzen.Blazor.ValidatorBase.md): BuildRenderTree, Component, Dispose, EditContext, Form, GetComponentCssClass, IsValid, OnAfterRenderAsync, Popup, PopupPosition, SetParametersAsync, messages
- From [RadzenComponent](https://blazor.radzen.com/docs/api/Radzen.RadzenComponent.md): AddContextMenu, Attributes, ContextMenu, Culture, CurrentStyle, Debounce, DefaultCulture, DefaultUICulture, Element, GetCssClass, GetId, GetIdAttribute, IsJSRuntimeAvailable, JSRuntime, Localize, MouseEnter, MouseLeave, OnBecameInvisible, OnContextMenu, OnInitialized, OnMouseEnter, OnMouseLeave, RaiseContextMenu, RaiseMouseEnter, RaiseMouseLeave, Reference, Style, UICulture, UniqueID, Visible
- From ComponentBase: Assets, AssignedRenderMode, DispatchExceptionAsync, InvokeAsync, OnAfterRender, OnInitializedAsync, OnParametersSet, OnParametersSetAsync, RendererInfo, ShouldRender, StateHasChanged

