AppSettingsValidator 1.0.1

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

AppSettingsValidator

A .NET library for validating application settings and configuration values with a fluent API and attribute-based validation.

Features

  • Attribute-based validation for configuration properties
  • Support for common validation rules:
    • Required fields
    • Minimum length
    • Email validation
    • Numeric range validation
    • Boolean validation
    • Phone number validation with support for 200+ countries
  • Fluent API for custom validation rules
  • Detailed validation error reporting
  • Easy integration with dependency injection

Installation

dotnet add package AppSettingsValidator

Quick Start

Using Attributes

public class AppSettings
{
    [Required("Database:ConnectionString")]
    [MinLength("Database:ConnectionString", 10)]
    public string ConnectionString { get; set; }

    [Email("Admin:Email")]
    public string AdminEmail { get; set; }

    [Range("Server:Port", 1, 65535)]
    public int Port { get; set; }

    [Boolean("Feature:Enabled")]
    public bool FeatureEnabled { get; set; }

    [PhoneNumber("Contact:Phone", "US")]
    public string PhoneNumber { get; set; }
}

Using Fluent API

var validator = new ConfigurationValidator();
validator.AddRule(ValidationRuleBuilder.Required("Database:ConnectionString"));
validator.AddRule(ValidationRuleBuilder.Email("Admin:Email"));
validator.AddRule(ValidationRuleBuilder.Range("Server:Port", 1, 65535));
validator.AddRule(ValidationRuleBuilder.Boolean("Feature:Enabled"));
validator.AddRule(ValidationRuleBuilder.PhoneNumber("Contact:Phone", "US"));

var result = validator.Validate(configuration);
if (!result.IsValid)
{
    foreach (var error in result.Errors)
    {
        Console.WriteLine(error);
    }
}

Supported Phone Number Formats

The library supports phone number validation for over 200 countries and territories, including:

  • North America (US, Canada, Mexico)
  • Europe (UK, Germany, France, etc.)
  • Asia (China, Japan, India, etc.)
  • South America (Brazil, Argentina, etc.)
  • Africa (South Africa, Egypt, etc.)
  • Oceania (Australia, New Zealand, etc.)
  • Middle East (Saudi Arabia, UAE, etc.)

Phone numbers can be validated in both international format (with country code) and national format.

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 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 was computed.  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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 125 6/6/2025