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

Must be a valid email, 5-100 characters0/100
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

Try leaving this empty

EmailValidator

Try: test@example.com (valid) or invalid-email (invalid)

StringLengthValidator - Minimum Length

Must be at least 5 characters

StringLengthValidator - Maximum Length

Must not exceed 10 characters0/10

StringLengthValidator - Length Range

Must be between 5 and 15 characters0/15

URLValidator

Must be absolute URL with scheme

PhoneValidator

Try: +1-555-123-4567, (555) 123-4567

RegexValidator - Alphanumeric Only

Letters and numbers only

CompareValidator

Create a password
Must match the password above

CustomValidator

Must be an even number
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.

Required field
Required field
We'll never share your email
3-20 characters, letters and numbers only0/20
At least 8 characters0/100
Must match the password above
Must be 18 or older
International format accepted
Your personal or company website
Brief description (max 500 characters)0/500

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)

13-digit personal ID starting with 0 or 20/13

IDNO (Organization Identification Number)

13-digit organization ID starting with 10/13

IDNX (Universal Identification Number)

Accepts IDNP or IDNO format0/13

IDNV (State Vehicle Identification Number)

13-digit vehicle ID starting with 30/13

Cadastral Code - Terrain Format

Format: AAAAAAA.BBB or AAAAAAA.BBBB

Cadastral Code - Construction Format

Format: AAAAAAA.BBB.CC or AAAAAAA.BBB.CCC

Cadastral Code - Isolated Room Format

Format: AAAAAAA.BBB.CC.DDDD

CUATM (Territory Classification Code)

4-digit territory classification code0/4

CAEM (Economic Activity Classifier)

Format: XX.XX (e.g., 62.01 Programming)

Moldova Phone Number

Supports mobile, landline, and special service numbers
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.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.