# RadzenDataAnnotationValidator Class

A validator component that validates form inputs using Data Annotations attributes defined on model properties. RadzenDataAnnotationValidator enables automatic validation based on attributes like [Required], [StringLength], [Range], [EmailAddress], etc. Must be placed inside a [RadzenTemplateForm<T>](https://blazor.radzen.com/docs/api/Radzen.Blazor.RadzenTemplateForm-1.md). Uses the standard .NET validation attributes from System.ComponentModel.DataAnnotations. Reads all validation attributes on a model property and validates the input accordingly. Benefits include centralized validation (define rules once on the model, use everywhere), support for multiple validation attributes per property, built-in attributes (Required, StringLength, Range, EmailAddress, Phone, Url, RegularExpression, etc.), works with custom ValidationAttribute implementations, and multiple errors joined with MessageSeparator. Ideal when your validation rules are already defined on your data models using data annotations. Automatically extracts error messages from the attributes' ErrorMessage properties.

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)
- RadzenDataAnnotationValidator

## Implements

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

## Syntax

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

## Examples

Model-based validation with data annotations:

```razor
<RadzenTemplateForm TItem="UserModel" Data=@user>
    <RadzenTextBox Name="Email" @bind-Value=@user.Email />
    <RadzenDataAnnotationValidator Component="Email" />
</RadzenTemplateForm>
@code {
    class UserModel
    {
        [Required(ErrorMessage = "Email is required")]
        [EmailAddress(ErrorMessage = "Invalid email format")]
        [StringLength(100, ErrorMessage = "Email too long")]
        public string Email { get; set; }
    }
    UserModel user = new UserModel();
}
```

Custom error separator:

```razor
<RadzenDataAnnotationValidator Component="Name" MessageSeparator=" | " />
```

## Constructors

| Constructor | Description |
|-------------|-------------|
| `public RadzenDataAnnotationValidator()` | A validator component that validates form inputs using Data Annotations attributes defined on model properties. RadzenDataAnnotationValidator enables automatic validation based on attributes like [Required], [StringLength], [Range], [EmailAddress], etc. Must be placed inside a [RadzenTemplateForm<T>](https://blazor.radzen.com/docs/api/Radzen.Blazor.RadzenTemplateForm-1.md). Uses the standard .NET validation attributes from System.ComponentModel.DataAnnotations. Reads all validation attributes on a model property and validates the input accordingly. Benefits include centralized validation (define rules once on the model, use everywhere), support for multiple validation attributes per property, built-in attributes (Required, StringLength, Range, EmailAddress, Phone, Url, RegularExpression, etc.), works with custom ValidationAttribute implementations, and multiple errors joined with MessageSeparator. Ideal when your validation rules are already defined on your data models using data annotations. Automatically extracts error messages from the attributes' ErrorMessage properties. |

## Properties

| Property | Type | Description |
|------|------|-------------|
| MessageSeparator | `string` | Gets or sets the text used to join multiple validation error messages. When multiple data annotation attributes fail (e.g., both Required and StringLength), their messages are combined with this separator. |
| ServiceProvider | `IServiceProvider` | Service provider injected from the Dependency Injection (DI) container. |
| Text | `string` | Gets or sets the validation error message. This property is automatically populated with error messages from data annotation attributes when validation fails. If multiple attributes fail, messages are joined using MessageSeparator. |

## 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

