NuvTools.Validation 10.1.0

dotnet add package NuvTools.Validation --version 10.1.0
                    
NuGet\Install-Package NuvTools.Validation -Version 10.1.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.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NuvTools.Validation" Version="10.1.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.1.0
                    
#r "nuget: NuvTools.Validation, 10.1.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.1.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.1.0
                    
Install as a Cake Addin
#tool nuget:?package=NuvTools.Validation&version=10.1.0
                    
Install as a Cake Tool

NuvTools Validation Libraries

NuGet License: MIT

A comprehensive validation library for .NET applications, providing robust validation features for Web, Desktop, and Mobile (MAUI) applications. Includes specialized validators for Brazilian documents, password complexity rules, and seamless integration with Blazor and FluentValidation. These libraries target modern .NET platforms, including .NET 8, .NET 9, and .NET 10.

Libraries

NuvTools.Validation

Core validation library with Brazilian document validators, regex patterns, and data annotations.

Key Features:

  • Brazilian Document Validators: CPF, CNPJ, mobile phone, and ZIP code (CEP) validation
  • General Validators: Email, numeric types (int, long, decimal), Base64/Data URI validation
  • Data Annotations: CPF/CNPJ attributes, password complexity attributes
  • Formatting Utilities: CPF and CNPJ formatting helpers

NuvTools.Validation.AspNetCore.Blazor

Blazor integration for FluentValidation with EditContext and ValidationMessageStore support.

Key Features:

  • FluentValidation Integration: Bridges FluentValidation with Blazor's EditContext
  • Auto-Validation: Automatic validation on form submission and field change
  • Nested Properties: Support for nested property path validation
  • Field Highlighting: Configurable invalid field highlighting via ValidationMessageStore

Installation

Install via NuGet Package Manager:

# For core validation features
dotnet add package NuvTools.Validation

# For Blazor applications with FluentValidation
dotnet add package NuvTools.Validation.AspNetCore.Blazor

Or via Package Manager Console:

Install-Package NuvTools.Validation
Install-Package NuvTools.Validation.AspNetCore.Blazor

Quick Start

Brazilian Document Validation

using NuvTools.Validation.Brazil;

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

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

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

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

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

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 value = "123.45";
bool isDecimal = value.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
    }
}

Features

  • Multi-targeting: Compatible with .NET 8, .NET 9, and .NET 10
  • Comprehensive documentation: Full XML documentation for IntelliSense
  • Modular design: Use only what you need
  • Modern C# features: Uses nullable reference types, implicit usings, and source-generated regex

Building from Source

This project uses the modern .slnx solution format (Visual Studio 2022 v17.11+).

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

# Build the solution
dotnet build NuvTools.Validation.slnx

# Run tests
dotnet test NuvTools.Validation.slnx

# Create release packages
dotnet build NuvTools.Validation.slnx --configuration Release

Requirements

  • .NET 8.0 SDK or higher
  • Visual Studio 2022 (v17.11+) or Visual Studio Code with C# extension
  • FluentValidation 12.x (for NuvTools.Validation.AspNetCore.Blazor)

Contributing

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

License

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

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 (1)

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

Package Downloads
NuvTools.Security.Identity.Models

ASP.NET Identity base models, form DTOs, and API models with localized validation for user and role management.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.1.0 272 1/28/2026
10.0.0 337 12/6/2025
9.5.1 158 11/1/2025
9.5.0 286 10/26/2025
9.1.0 1,721 4/1/2025
9.0.0 310 11/13/2024
8.1.1 226 9/11/2024
8.1.0 348 5/27/2024
8.0.1 354 4/8/2024
8.0.0 292 2/14/2024
7.0.0 903 2/26/2023