Altairis.ValidationToolkit
3.0.1
See the version list below for details.
dotnet add package Altairis.ValidationToolkit --version 3.0.1
NuGet\Install-Package Altairis.ValidationToolkit -Version 3.0.1
<PackageReference Include="Altairis.ValidationToolkit" Version="3.0.1" />
paket add Altairis.ValidationToolkit --version 3.0.1
#r "nuget: Altairis.ValidationToolkit, 3.0.1"
// 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
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, useEmptyBankCodeValidator
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 andDateTime.Today
.[DateOffset(null, "30.00.00.00")]
- date must be betweenDateTime.Now
andDateTime.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 propertyMinimum
.[GreaterThan("Minimum", AllowEqual = true)]
- value of this property must be greater or equal to value of propertyMinimum
.
[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 whenOtherProperty == "value"
.[RequiredWhen("OtherProperty", "value", NegateCondition = true)]
- property is required whenOtherProperty != "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 whenOtherProperty == "value"
.[RequiredEmptyWhen("OtherProperty", "value", NegateCondition = true)]
- property is required to be empty whenOtherProperty != "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 | Versions 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. |
-
.NETStandard 2.0
- System.ComponentModel.Annotations (>= 5.0.0)
-
net7.0
- System.ComponentModel.Annotations (>= 5.0.0)
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 |
---|---|---|
4.1.1 | 237 | 8/16/2024 |
4.1.0 | 137 | 5/28/2024 |
4.0.0 | 100 | 5/28/2024 |
3.0.1 | 2,653 | 10/30/2023 |
3.0.0 | 245 | 7/15/2023 |
2.9.2 | 2,206 | 12/6/2021 |
2.9.1 | 435 | 3/22/2021 |
2.9.0 | 444 | 1/18/2021 |
2.8.0 | 463 | 12/14/2020 |
2.7.0 | 685 | 7/15/2020 |
2.6.1 | 553 | 7/3/2020 |
2.6.0 | 489 | 7/1/2020 |
2.5.0 | 16,177 | 5/27/2019 |
2.0.0 | 11,425 | 12/19/2017 |
1.2.0 | 5,177 | 9/16/2015 |
1.1.0 | 1,730 | 9/19/2014 |
1.0.1 | 2,261 | 4/18/2014 |
1.0.0 | 1,553 | 4/18/2014 |