Tooark.Attributes 4.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tooark.Attributes --version 4.4.0
                    
NuGet\Install-Package Tooark.Attributes -Version 4.4.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="Tooark.Attributes" Version="4.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tooark.Attributes" Version="4.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Tooark.Attributes" />
                    
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 Tooark.Attributes --version 4.4.0
                    
#r "nuget: Tooark.Attributes, 4.4.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 Tooark.Attributes@4.4.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=Tooark.Attributes&version=4.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Tooark.Attributes&version=4.4.0
                    
Install as a Cake Tool

Tooark.Attributes

Library with attribute validators for properties or fields, integrated with System.ComponentModel.DataAnnotations.

🌍 Languages: 🇺🇸 English (this file) · 🇧🇷 Português

Installation

dotnet add package Tooark.Attributes

Contents

Validation Attributes

Every attribute accepts propertyName, which sets the field name used in the error message.

1. Document Validation

Purpose: Validates the document by format, with a regular expression, and by check digits.

Parameters:

  • string type: Type of document to validate. Required.
  • string propertyName: Field name in the error message. Default: "Document".

The type is received as text because attribute arguments accept constants only — a parameter of type EDocumentType would prevent the attribute from being applied (CS0181). Accepted values, case-insensitive: CPF, RG, CNH, CNPJ, CPF_CNPJ, CPF_RG, CPF_RG_CNH and None.

An unrecognized type is a configuration error and makes the attribute throw InternalServerErrorException on the first validation, with the message Attributes.DocumentTypeUnknown;{type}.

Usage Example

2. Email Validation

Purpose: Validates whether the value is a valid email address.

Parameters:

  • string propertyName: Field name in the error message. Default: "Email".

Usage Example

Purpose: Validates whether the value is a video link from one of the enabled providers.

Parameters:

  • string propertyName: Field name in the error message. Default: "Link".
  • bool youtube: Allows YouTube links. Default: true.
  • bool vimeo: Allows Vimeo links. Default: true.
  • bool dailymotion: Allows Dailymotion links. Default: true.

Disabling all three providers is a configuration error — no link could be accepted — and makes the attribute throw InternalServerErrorException with the message Attributes.LinkVideoNoProvider;{field}.

Usage Example

4. Password Validation

Purpose: Validates whether the password meets the configured complexity criteria.

Parameters:

  • bool lowercase: Requires a lowercase character. Default: true.
  • bool uppercase: Requires an uppercase character. Default: true.
  • bool number: Requires a numeric character. Default: true.
  • bool symbol: Requires a special character. Default: true.
  • int length: Minimum length. Default: 8. A non-positive value assumes 1.
  • string propertyName: Field name in the error message. Default: "Password".

The criteria apply exactly as configured. Disabling all of them means requiring only the length, which is a legitimate policy: long passwords with no composition rule.

Usage Example

5. URL Validation

Purpose: Validates whether the value is a valid URL in the email (sending and receiving), FTP, HTTP or WebSocket protocols.

Parameters:

  • string propertyName: Field name in the error message. Default: "Url".

Usage Example

6. Zip Code Validation

Purpose: Validates whether the value is a valid zip code.

Parameters:

  • string propertyName: Field name in the error message. Default: "ZipCode".

Usage Example

Common behavior

Every attribute inherits from TooarkValidationAttribute and shares the rules below.

Error messages. The message is returned in the ValidationResult of each validation, and never written to ErrorMessage. That matters because the validation framework reuses the same attribute instance across every validation of that field, including concurrent ones: writing to the attribute would mix one request's message with another's.

Without configuration, the message is a translation key in the Key;Field format:

Situation Message
Field not provided Field.Required;{field}
Value does not match the rule Field.Invalid;{field}

If you configure ErrorMessage or ErrorMessageResourceName on the attribute, that message is used instead of the key.

Missing value. A null, empty or whitespace-only value is reported as Field.Required. In other words, the attributes imply being required — they do not follow the DataAnnotations convention, in which validators other than [Required] accept null. For an optional field, validate outside the attribute or apply it conditionally.

Non-text values. The value is converted with ToString() before validation, so a Uri or a custom type with a suitable ToString() works.

Regular expression timeout. Every regular expression runs with a 300 ms limit. Input that causes excessive backtracking is rejected, and the exception does not escape the attribute.

Configuration error. An impossible configuration — unknown document type, video link with no provider — throws InternalServerErrorException on the first validation. It is not a failure of the data but of the attribute applied in code; the keys are in Tooark.Attributes.Messages.AttributeErrorMessages.

Usage Example

Document Validation

using Tooark.Attributes;

public class Person
{
  [DocumentValidation("CPF")]
  public string Cpf { get; set; } = null!;

  [DocumentValidation("CPF_CNPJ", propertyName: "Document")]
  public string Document { get; set; } = null!;
}

Email Validation

using Tooark.Attributes;

public class Contact
{
  [EmailValidation]
  public string Email { get; set; } = null!;

  // With a custom message, which takes precedence over the default key
  [EmailValidation(ErrorMessage = "Provide a corporate email")]
  public string CorporateEmail { get; set; } = null!;
}
using Tooark.Attributes;

public class Lesson
{
  [LinkVideoValidation]
  public string Video { get; set; } = null!;

  // YouTube only, with a custom field name in the message
  [LinkVideoValidation("Presentation", youtube: true, vimeo: false, dailymotion: false)]
  public string Presentation { get; set; } = null!;
}

Password Validation

using Tooark.Attributes;

public class Credential
{
  [PasswordValidation]
  public string Password { get; set; } = null!;

  // Passphrase: no composition rule, minimum length of 20
  [PasswordValidation(false, false, false, false, 20)]
  public string Passphrase { get; set; } = null!;
}

URL Validation

using Tooark.Attributes;

public class Site
{
  [UrlValidation]
  public string Address { get; set; } = null!;
}

Zip Code Validation

using Tooark.Attributes;

public class Address
{
  [ZipCodeValidation]
  public string ZipCode { get; set; } = null!;
}

Reading the validation result

using System.ComponentModel.DataAnnotations;

var person = new Person { Cpf = "11111111111" };
var results = new List<ValidationResult>();

Validator.TryValidateObject(person, new ValidationContext(person), results, true);

foreach (var result in results)
{
  // result.ErrorMessage -> "Field.Invalid;Document"
  // result.MemberNames  -> ["Cpf"]
}

Dependencies

Contributing

Contributions are welcome! Feel free to open issues and pull requests in the Tooark.Attributes repository.

License

This project is licensed under the BSD 3-Clause 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 was computed.  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.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Tooark.Attributes:

Package Downloads
Tooark

Package with all Tooark resources for .NET applications.

Tooark.AspNetCore

Package with the ASP.NET Core specific pieces of Tooark for .NET applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.7.1 38 10/17/2026
4.7.0 311 9/30/2026
4.6.0 145 9/29/2026
4.5.0 120 9/29/2026
4.4.0 110 9/28/2026
4.3.0 112 9/26/2026
4.2.1 114 9/25/2026
4.2.0 124 9/20/2026
4.1.0 110 9/18/2026
4.0.1 125 8/25/2026
4.0.0 131 8/25/2026
3.3.6 114 9/18/2026
3.3.5 122 8/25/2026
3.3.4 129 8/12/2026
3.3.3 139 7/27/2026
3.3.2 280 6/11/2026
3.3.1 158 6/6/2026
2.3.5 102 9/18/2026
2.3.4 117 8/25/2026
2.3.3 125 7/27/2026
Loading failed