Validity.DataAnnotation 2.2.3

dotnet add package Validity.DataAnnotation --version 2.2.3                
NuGet\Install-Package Validity.DataAnnotation -Version 2.2.3                
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="Validity.DataAnnotation" Version="2.2.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Validity.DataAnnotation --version 2.2.3                
#r "nuget: Validity.DataAnnotation, 2.2.3"                
#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.
// Install Validity.DataAnnotation as a Cake Addin
#addin nuget:?package=Validity.DataAnnotation&version=2.2.3

// Install Validity.DataAnnotation as a Cake Tool
#tool nuget:?package=Validity.DataAnnotation&version=2.2.3                

1. Install package

dotnet add package Validity.DataAnnotation

2. Create Class

public class MyClass
{
     [Phone]
     public string PhoneNumber { get; set; }
     public NestedClass Nested { get; set; }
}

public class NestedClass
{
     [MaxLength(5)]
     public string Title { get; set; }
}

3. Add validator to service container

in Program.cs

 builder.Services.AddObjectValidator();

4. Inject validator to yout controller

[ApiController]
[Route("api/[controller]")]
public class MyController : ControllerBase
{
    readonly IObjectValidator _validator;

    public MyController(IObjectValidator validator)
    {
        _validator = validator;
    }
}

5. Use validator

[HttpPost]
public IActionResult AddUser(MyClass myClass)
{
    var validationErrors = _validator.Validate(myClass);

    if (validationErrors.Count != 0)
    {
        //DO SOMETHING
    }
}
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. 
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
2.2.3 94 10/3/2024
2.2.2 135 8/20/2024
2.2.1 116 8/20/2024
2.1.12 124 8/17/2024
2.1.11 111 8/17/2024
2.1.3 117 8/20/2024
2.1.2 106 8/20/2024
2.1.1 102 7/14/2024
2.1.0 100 7/13/2024
2.0.1 105 7/7/2024
2.0.0 96 7/7/2024
1.3.0 94 7/3/2024
1.2.0 111 6/28/2024
1.0.0 100 6/12/2024