NuvTools.Validation 10.0.0

dotnet add package NuvTools.Validation --version 10.0.0
                    
NuGet\Install-Package NuvTools.Validation -Version 10.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NuvTools.Validation" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NuvTools.Validation" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NuvTools.Validation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NuvTools.Validation --version 10.0.0
                    
#r "nuget: NuvTools.Validation, 10.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NuvTools.Validation@10.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NuvTools.Validation&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NuvTools.Validation&version=10.0.0
                    
Install as a Cake Tool

NuvTools Validation Library

NuGet License

NuvTools Validation is a comprehensive validation library for .NET 8, 9, and 10, designed to provide robust validation features for Web, Desktop, and Mobile (MAUI) applications. It includes specialized validators for Brazilian documents, password complexity rules, and seamless integration with Blazor and FluentValidation.

📦 Packages

Package Version Description
NuvTools.Validation NuGet Core validation library with Brazilian validators, regex patterns, and data annotations
NuvTools.Validation.AspNetCore.Blazor NuGet Blazor integration with FluentValidation support

🚀 Installation

Install via NuGet Package Manager:

dotnet add package NuvTools.Validation

For Blazor applications with FluentValidation:

dotnet add package NuvTools.Validation.AspNetCore.Blazor

✨ Features

Core Validation (NuvTools.Validation)

  • Brazilian Document Validators

    • CPF (Cadastro de Pessoas Físicas) validation
    • CNPJ (Cadastro Nacional da Pessoa Jurídica) validation
    • Brazilian mobile phone number validation
    • ZIP code (CEP) validation
    • Auto-detection of CPF or CNPJ
  • General Validators

    • Email address validation
    • Numeric validation (int, long, decimal)
    • Base64 content and Data URI validation
  • Data Annotations

    • CPF/CNPJ validation attributes
    • Password complexity attributes (capital letters, lowercase, digits)
    • Custom validation attributes
  • Formatting Utilities

    • CPF formatting (XXX.XXX.XXX-XX)
    • CNPJ formatting (XX.XXX.XXX/XXXX-XX)

Blazor Integration (NuvTools.Validation.AspNetCore.Blazor)

  • FluentValidation integration with EditContext
  • MudBlazor MudForm integration via PropertyValidatorBase
  • Automatic validation on form submission
  • Field-level validation on change
  • Support for nested property validation
  • ValidationMessageStore integration

📖 Usage Examples

Brazilian Document Validation

using NuvTools.Validation.Brazil;

// Validate CPF
string cpf = "123.456.789-01";
bool isValid = cpf.IsCPF(); // Returns true or false

// Validate CNPJ
string cnpj = "12.345.678/0001-95";
bool isValid = cnpj.IsCNPJ(); // Returns true or false

// Auto-detect CPF or CNPJ
string document = "12345678901";
bool isValid = document.IsCPForCNPJ(); // Validates based on length

// Validate mobile phone
string phone = "11987654321";
bool isValid = phone.IsMobileNumber(); // Validates Brazilian mobile format

// Validate ZIP code (CEP)
string zipCode = "01310-100";
bool isValid = zipCode.IsZipCodeNumber(); // Validates format

Document Formatting

using NuvTools.Validation.Brazil;

// Format CPF
string cpf = "12345678901";
string formatted = cpf.FormatCPF(); // Returns "123.456.789-01"

// Format CNPJ
string cnpj = "12345678000195";
string formatted = cnpj.FormatCNPJ(); // Returns "12.345.678/0001-95"

General Validation

using NuvTools.Validation;

// Email validation
string email = "user@example.com";
bool isValid = email.IsEmail();

// Numeric validation
string number = "12345";
bool isInt = number.IsIntNumber();
bool isPositive = number.IsIntNumber(positiveOnly: true);
bool isLong = number.IsLongNumber();

// Decimal validation
string decimal = "123.45";
bool isDecimal = decimal.IsDecimalNumber();

Data Annotations

using NuvTools.Validation.Brazil.Annotations;
using NuvTools.Validation.Annotations;

public class UserRegistrationModel
{
    [Required]
    [CPF]
    public string CPF { get; set; }

    [Required]
    [PasswordComplexityCapitalLetters(2)]
    [PasswordComplexityLowerCaseLetters(2)]
    [PasswordComplexityDigits(2)]
    public string Password { get; set; }
}

public class CompanyModel
{
    [Required]
    [CNPJ]
    public string CNPJ { get; set; }
}

// Validate using data annotations
var model = new UserRegistrationModel
{
    CPF = "123.456.789-01",
    Password = "MyPass123"
};

var errors = model.Validate(); // Returns null if valid, or list of error messages

Blazor FluentValidation Integration

@page "/register"
@using NuvTools.Validation.AspNetCore.Blazor
@using FluentValidation

<EditForm Model="@model" OnValidSubmit="HandleSubmit">
    <NuvTools.Validation.AspNetCore.Blazor.FluentValidation TModel="UserModel"
        @ref="fluentValidation"
        Validator="validator"
        Model="model"
        EditContext="editContext" />

    <InputText @bind-Value="model.Name" />
    <ValidationMessage For="() => model.Name" />

    <InputText @bind-Value="model.Address.City" />
    <ValidationMessage For="() => model.Address.City" />

    <button type="submit">Submit</button>
</EditForm>

@code {
    private UserModel model = new();
    private EditContext editContext;
    private UserModelValidator validator = new();
    private FluentValidation<UserModel> fluentValidation;

    protected override void OnInitialized()
    {
        editContext = new EditContext(model);
        fluentValidation = new FluentValidation<UserModel>(
            model,
            validator,
            editContext,
            autoValidationOnRequested: true,
            autoValidationOnFieldChanged: true
        );
    }

    public class UserModel
    {
        public string Name { get; set; }
        public Address Address { get; set; } = new();
    }

    public class Address
    {
        public string City { get; set; }
    }

    public class UserModelValidator : AbstractValidator<UserModel>
    {
        public UserModelValidator()
        {
            RuleFor(x => x.Name).NotEmpty();
            RuleFor(x => x.Address.City).NotEmpty();
        }
    }

    private void HandleSubmit()
    {
        // Form is valid
    }
}

MudBlazor Integration with PropertyValidatorBase

The PropertyValidatorBase class is specifically designed for use with MudBlazor forms. MudForm components automatically call the ValidatePropertyAsync delegate for field-level validation.

@page "/register"
@using MudBlazor
@using NuvTools.Validation.AspNetCore.Blazor.FluentValidation
@using FluentValidation

<MudForm Model="@model" @ref="form" Validation="@(validator.ValidatePropertyAsync)">
    <MudTextField @bind-Value="model.Email"
                  For="@(() => model.Email)"
                  Label="Email"
                  Required="true" />

    <MudTextField @bind-Value="model.Name"
                  For="@(() => model.Name)"
                  Label="Name"
                  Required="true" />

    <MudTextField @bind-Value="model.Password"
                  For="@(() => model.Password)"
                  Label="Password"
                  InputType="InputType.Password"
                  Required="true" />

    <MudButton Variant="Variant.Filled"
               Color="Color.Primary"
               OnClick="@(async () => await Submit())">
        Register
    </MudButton>
</MudForm>

@code {
    private MudForm form;
    private UserModel model = new();
    private UserModelValidator validator = new();

    public class UserModel
    {
        public string Email { get; set; }
        public string Name { get; set; }
        public string Password { get; set; }
    }

    public class UserModelValidator : PropertyValidatorBase<UserModel>
    {
        public UserModelValidator()
        {
            RuleFor(x => x.Email)
                .NotEmpty().WithMessage("Email is required")
                .EmailAddress().WithMessage("Invalid email format");

            RuleFor(x => x.Name)
                .NotEmpty().WithMessage("Name is required")
                .MinimumLength(3).WithMessage("Name must be at least 3 characters");

            RuleFor(x => x.Password)
                .NotEmpty().WithMessage("Password is required")
                .MinimumLength(8).WithMessage("Password must be at least 8 characters");
        }
    }

    private async Task Submit()
    {
        await form.Validate();

        if (form.IsValid)
        {
            // Process the valid form
        }
    }
}

🎯 Supported Frameworks

  • .NET 8
  • .NET 9
  • .NET 10

🔧 Building from Source

# Clone the repository
git clone https://github.com/nuvtools/nuvtools-validation.git
cd nuvtools-validation

# Build the solution
dotnet build NuvTools.Validation.slnx -c Release

# Run tests
dotnet test NuvTools.Validation.slnx -c Release

# Create NuGet packages
dotnet pack NuvTools.Validation.slnx -c Release

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

💡 Support

If you encounter any issues or have questions, please open an issue on GitHub.


Copyright © 2025 Nuv Tools

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on NuvTools.Validation:

Package Downloads
NuvTools.Security

Common library for security purposes.

NuvTools.Security.Identity.Models

Contains models to be used with ASP.NET Identity modules.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0 301 12/6/2025
9.5.1 138 11/1/2025
9.5.0 266 10/26/2025
9.1.0 1,709 4/1/2025
9.0.0 288 11/13/2024
8.1.1 212 9/11/2024
8.1.0 332 5/27/2024
8.0.1 334 4/8/2024
8.0.0 272 2/14/2024
7.0.0 882 2/26/2023