Altairis.ValidationToolkit 3.0.1

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

// Install Altairis.ValidationToolkit as a Cake Tool
#tool nuget:?package=Altairis.ValidationToolkit&version=3.0.1

NuGet Status

Altairis Validation Toolkit

Set of various interesting .NET validation attributes, usable for example in ASP.NET MVC, Razor Pages, and Web Forms model binding. You can use them to decorate model and ViewModel properties.

The library is compatible with .NET Standard 2.0.

How to install

The best way to install this library is to use the Altairis.ValidationToolkit NuGet package.

Validation attributes included

[ColorAttribute]

Editor template name: Color.

Validates if given string is a valid HTML color in the #RRGGBB syntax.

  • [Color] - string must ve valid HTML color (no options are available)

[CzechBankAccount]

Editor template name: CzechBankAccount.

Validates if given string is valid Czech bank account number. Expects value to be in form prefix-number/bankcode, where the prefix- part is optional.

  • [CzechBankAccount] - standard usage
  • <sup>obsolete</sup> [CzechBankAccount(IgnoreBankCode = true)] - will allow any four decimal number as a bank code. Deprecated, use EmptyBankCodeValidator instead.
Validating bank codes

By default, the validator uses hardcoded list of valid bank codes, taken from the Czech National Bank website. The values are fairly static, usually only the company names (which are not used) are changed, not the numbers themselves. But the validation mechanism is extensible.

You can use the OnlineBankCodeValidator, which downloads the list of valid codes from CNB website. To do that, register the class to IoC/DI container:

services.AddSingleton<IBankCodeValidator>(new OnlineBankCodeValidator());

You can also turn off the bank code validation globally by using the EmptyBankCodeValidator, which will validate any four digit number:

services.AddSingleton<IBankCodeValidator>(new EmptyBankCodeValidator());

Additionally, you can create your own validator by implementing the IBankCodeValidator interface.

[DateOffset]

Validates if given DateTime falls within defined offset from current date. Useful for validating birthdates etc.

  • [DateOffset(-120, 0)] - date must be between 120 years ago and DateTime.Today.
  • [DateOffset(null, "30.00.00.00")] - date must be between DateTime.Now and DateTime.Now + 30 days.

Please note: By default, the attribute ignores time of day when comparing. If you want to take it in account, set CompareTime to true and modify error message formatting to show the time of day as well.

[GreaterThan]

Validates if given value is greater than value of some other property.

  • [GreaterThan("Minimum")] - value of this property must be greater than value of property Minimum.
  • [GreaterThan("Minimum", AllowEqual = true)] - value of this property must be greater or equal to value of property Minimum.

[Ico]

Editor template name: Ico.

Validates if given string is valid IČO (identification number of person, the state-issued identifier used in Czech Republic).

  • [Ico] - string must be valid IČO (no options are available)

[YearOffset]

Validates if given year (expressed as int) falls within defined offset from current year. Useful for validating birthdates etc.

  • [YearOffset(-120, 0)] - year must be between from 120 years ago and current year.
  • [YearOffset(0, 10)] - year must be in next 10 years from now.

[RequiredWhen]

Makes property required when some other property has specific value.

  • [RequiredWhen("OtherProperty", "value")] - property is required when OtherProperty == "value".
  • [RequiredWhen("OtherProperty", "value", NegateCondition = true)] - property is required when OtherProperty != "value".

Please note: The default error message does not mention the master condition (it says Field {0} is required, not Field {0} is required when some conditions are met). It's recommended to override the message to be more specific to your model.

[RequiredEmptyWhen]

Complements the RequiredWhen attribute. Forces property to have null value when other property has specific value.

  • [RequiredEmptyWhen("OtherProperty", "value")] - property is required to be empty when OtherProperty == "value".
  • [RequiredEmptyWhen("OtherProperty", "value", NegateCondition = true)] - property is required to be empty when OtherProperty != "value".

Please note: The default error message does not mention the master condition (it says Field {0} is required to be empty, not Field {0} is required to be empty when some conditions are met). It's recommended to override the message to be more specific to your model.

[RodneCislo]

Editor template name: RodneCislo._

Validates if a given string is valid rodné číslo ("birth number" the personal identifier of a physical person used in Czech republic). The validation algorithm is derived from § 13 of the Czech law no. 133/2000.

  • [RodneCislo] - validates the correct format (no options are available).
Parsing

There is also class Altairis.ValidationToolkit.LogicalTypes.RodneCislo which represents the logical data type.

Use the Parse and TryParse methods to parse strings as rodné číslo. All characters except decimal numbers are ignored. Instance has the following read-only properties:

  • BirthDate - date of birth of the person.
  • SequenceNumber - number discriminating persons born on the same day.
  • Gender - male or female.
  • IsExtraSequence - determines where second set of sequence numbers was used.

Instance has the following methods:

  • ToString() - returns value with / separator;
  • ToString(useSeparator: false) - returns value without the separator.

License

This library is open source software licensed under terms of the MIT License.

Contributor Code of Conduct

This project adheres to No Code of Conduct. We are all adults. We accept anyone's contributions. Nothing else matters.

For more information please visit the No Code of Conduct homepage.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
3.0.1 915 10/30/2023
3.0.0 212 7/15/2023
2.9.2 1,220 12/6/2021
2.9.1 404 3/22/2021
2.9.0 410 1/18/2021
2.8.0 435 12/14/2020
2.7.0 649 7/15/2020
2.6.1 525 7/3/2020
2.6.0 462 7/1/2020
2.5.0 13,921 5/27/2019
2.0.0 9,521 12/19/2017
1.2.0 5,102 9/16/2015
1.1.0 1,696 9/19/2014
1.0.1 2,204 4/18/2014
1.0.0 1,515 4/18/2014