Validation System

The FOD validation system provides comprehensive validators with fluent API chaining, localization support, and seamless integration with form components.

Quick Start

Use the fluent ValidatorExtensions.For<T>() API to chain validators together.

Fluent API Example

Value: (empty)
csharp
// Chain validators using fluent API
var validation = ValidatorExtensions
    .For<string>()
    .Required()
    .Email()
    .MinLength(5)
    .MaxLength(100)
    .ToValidationWithLabel();

// Use with FodTextField
<FodTextField Label="Email"
              @bind-Value="@email"
              Validation="@validation" />

Validators Reference

Complete reference of all built-in validators with live interactive examples.

RequiredValidator

EmailValidator

StringLengthValidator - Minimum Length

StringLengthValidator - Maximum Length

StringLengthValidator - Length Range

URLValidator

PhoneValidator

RegexValidator - Alphanumeric Only

CompareValidator

CustomValidator

csharp
// RequiredValidator
.Required()

// EmailValidator
.Email()

// StringLengthValidator
.MinLength(5)
.MaxLength(10)
.StringLength(minLength: 5, maxLength: 15)

// URLValidator
.Url()

// PhoneValidator
.Phone()

// RegexValidator
.Regex(pattern: @"^[a-zA-Z0-9]+$", errorMessage: "Only alphanumeric")

// CompareValidator
.Compare(_ => passwordValue, comparisonPropertyName: "Password")

// CustomValidator
.Custom((value, context) => int.TryParse(value, out var num) && num % 2 == 0,
        errorMessage: "Must be an even number")

Complete Form Example

User registration form demonstrating validation with multiple fields and error handling.

Submit Reset

Current form values:

First Name: (empty)
                Last Name: (empty)
                Email: (empty)
                Username: (empty)
                Password: (empty)
                Confirm Password: (empty)
                Age: (empty)
                Phone Number (Optional): (empty)
                Website (Optional): (empty)
                Bio: (empty)
csharp
// Form validators with fluent API
_formEmailValidation = ValidatorExtensions.For<string>()
    .Required()
    .Email()
    .MaxLength(100)
    .ToValidationWithLabel();

_formUsernameValidation = ValidatorExtensions.For<string>()
    .Required()
    .MinLength(3)
    .MaxLength(20)
    .Regex(pattern: @"^[a-zA-Z0-9]+$",
           errorMessage: "Username can only contain letters and numbers")
    .ToValidationWithLabel();

// Custom age validation
_formAgeValidation = ValidatorExtensions.For<string>()
    .Required()
    .Custom((value, context) =>
    {
        if (int.TryParse(value, out var age))
            return age >= 18 && age <= 120;
        return false;
    }, errorMessage: "Age must be between 18 and 120")
    .ToValidationWithLabel();

Moldova Identifier Validators

Specialized validators for Moldova-specific identification numbers and codes.

IDNP (Personal Identification Number)

IDNO (Organization Identification Number)

IDNX (Universal Identification Number)

IDNV (State Vehicle Identification Number)

Cadastral Code - Terrain Format

Cadastral Code - Construction Format

Cadastral Code - Isolated Room Format

CUATM (Territory Classification Code)

CAEM (Economic Activity Classifier)

Moldova Phone Number

Mobile: 60, 68, 69, 610, 611, 620, 621, 671-677, 71, 760, 767, 780-788, 79
Landline: 22 (Chisinau), 230-239, 290-299, 533, 552, 555, 557
Special: 800 (toll-free), 808 (shared cost), 900/905/906 (premium), 30/38 (nomadic)
csharp
// IDNP - Personal Identification Number
.Idnp()

// IDNO - Organization Identification Number
.Idno()

// IDNX - Universal (IDNP or IDNO)
.Idnx()

// IDNV - State Vehicle Identification Number
.Idnv()

// Cadastral Code
.CadastralCode()

// CUATM - Territory Classification
.Cuatm()

// CAEM - Economic Activity Classifier
.Caem()

// Moldova Phone Number
.MoldovaPhone()

Accessibility & Best Practices

Guidelines for implementing accessible validation in your forms.

  • Validation error messages are linked via aria-describedby for screen readers
  • aria-invalid attribute is set when validation fails
  • Use clear, actionable error messages that explain how to fix the issue
  • Provide real-time feedback with Immediate mode and DebounceInterval
  • Use RequiredValidator with Required attribute for mandatory fields
  • Chain validators using the fluent API for complex validation rules
  • Implement IValidationMessageLocalizer for multi-language support
razor
<FodTextField Label="Email" Required="true" Validation="@_emailValidation" />

API Reference

Validation system types and their descriptions.

No properties defined.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

Retry

The session has been paused by the server.

Resume

Failed to resume the session.
Please reload the page.