Modern.FluentValidation.Extensions
1.0.0
See the version list below for details.
dotnet add package Modern.FluentValidation.Extensions --version 1.0.0
NuGet\Install-Package Modern.FluentValidation.Extensions -Version 1.0.0
<PackageReference Include="Modern.FluentValidation.Extensions" Version="1.0.0" />
paket add Modern.FluentValidation.Extensions --version 1.0.0
#r "nuget: Modern.FluentValidation.Extensions, 1.0.0"
// Install Modern.FluentValidation.Extensions as a Cake Addin #addin nuget:?package=Modern.FluentValidation.Extensions&version=1.0.0 // Install Modern.FluentValidation.Extensions as a Cake Tool #tool nuget:?package=Modern.FluentValidation.Extensions&version=1.0.0
Modern.FluentValidation.Extensions
A big set of custom validators for popular FluentValidation library for a daily usage
Installation
Install a FluentValidation.Extensions nuget package
Features
A list of validators:
- String validators
- Boolean validators
- Collection validators
- HasElements
- HasNoElements
- HasCountOfElements
- HasElementsMoreThan
- HasElementsMoreOrEqualThan
- HasElementsLessThan
- HasElementsLessOrEqualThan
- HasElementsBetweenExclusive
- HasElementsBetweenInclusive
- HasEvenCountOfElements
- HasOddCountOfElements
- IsUnique
- HasDuplicates
- NoNullElements
- AllMatch
- AnyMatch
- Contains
- DoesNotContain
- AllElementsOfType
- DateTime validators
- URL validators
String validators
Contains
Validates that the string contains a specified substring.
RuleFor(x => x.StringValue).Contains("foo");
DoesNotContain
Validates that the string does not contain a specified substring.
RuleFor(x => x.StringValue).DoesNotContain("foo");
StartsWith
Validates that the string starts with a specified substring.
RuleFor(x => x.StringValue).StartsWith("foo");
EndsWith
Validates that the string ends with a specified substring.
RuleFor(x => x.StringValue).EndsWith("foo");
DoesNotStartWith
Validates that the string does not start with a specified substring.
RuleFor(x => x.StringValue).DoesNotStartWith("foo");
DoesNotEndWith
Validates that the string does not end with a specified substring.
RuleFor(x => x.StringValue).DoesNotEndWith("foo");
LengthBetween
Validates that the length of the string is between the specified minimum and maximum.
RuleFor(x => x.StringValue).LengthBetween(5, 10);
BeNumeric
Validates that the string consists only of numeric characters.
RuleFor(x => x.StringValue).BeNumeric();
BeLatinLetters
Validates that the string consists only of Latin letters.
RuleFor(x => x.StringValue).BeLatinLetters();
NoSpecialCharacters
Validates that the string does not contain any special characters.
RuleFor(x => x.StringValue).NoSpecialCharacters();
If some special characters are allowed they can be passed inside a string parameter without delimeters:
RuleFor(x => x.StringValue).NoSpecialCharacters("_.");
Boolean validators
BeTrue
Validates that a value equals to true.
RuleFor(x => x.BooleanValue).BeTrue();
BeFalse
Validates that a value equals to false.
RuleFor(x => x.BooleanValue).BeFalse();
Collection validators
HasElements
Validates that a collection has elements.
RuleFor(x => x.CollectionProperty).HasElements();
HasNoElements
Validates that a collection has no elements.
RuleFor(x => x.CollectionProperty).HasNoElements();
HasCountOfElements
Validates that a collection has a given count of elements.
RuleFor(x => x.CollectionProperty).HasCountOfElements(5);
HasElementsMoreThan
Validates that a collection has more than N elements.
RuleFor(x => x.CollectionProperty).HasElementsMoreThan(5);
HasElementsMoreOrEqualThan
Validates that a collection has equal or more than N elements.
RuleFor(x => x.CollectionProperty).HasElementsMoreOrEqualThan(5);
HasElementsLessThan
Validates that a collection has less than N elements.
RuleFor(x => x.CollectionProperty).HasElementsLessThan(5);
HasElementsLessOrEqualThan
Validates that a collection has equal or less than N elements.
RuleFor(x => x.CollectionProperty).HasElementsLessOrEqualThan(5);
HasElementsBetweenExclusive
Validates that a collection has count of elements between N and M exclusively.
RuleFor(x => x.CollectionProperty).HasElementsBetweenExclusive(5, 10);
HasElementsBetweenInclusive
Validates that a collection has count of elements between N and M inclusively..
RuleFor(x => x.CollectionProperty).HasElementsBetweenInclusive(5, 10);
HasEvenCountOfElements
Validates that a collection has an even count of elements.
RuleFor(x => x.CollectionProperty).HasEvenCountOfElements();
HasOddCountOfElements
Validates that a collection has an odd count of elements.
RuleFor(x => x.CollectionProperty).HasOddCountOfElements();
IsUnique
Validates that a collection has all unique elements.
RuleFor(x => x.CollectionProperty).IsUnique();
HasDuplicates
Validates that a collection has at least one duplicate element.
RuleFor(x => x.CollectionProperty).HasDuplicates();
NoNullElements
Validates that a collection doesn't have null elements.
NOTE: this method treats default values of objects as null elements, like 0 for numbers and false for boolean
RuleFor(x => x.CollectionProperty).NoNullElements(5;
AllMatch
Validates that all elements of collection match the specified condition.
RuleFor(x => x.Persons).AllMatch(x => x.Age > 18);
AnyMatch
Validates that any element of collection matches the specified condition.
RuleFor(x => x.Persons).AnyMatch(x => x.Age > 18);
Contains element
Validates that a collection contains a specified value.
RuleFor(x => x.CollectionProperty).Contains(5);
DoesNotContain element
Validates that a collection has doesn't contain a specified value.
RuleFor(x => x.CollectionProperty).DoesNotContain(5);
AllElementsOfType
Validates that a collection has all objects of the specified type.
public class TestClass
{
public List<object> ObjectItems { get; set; } = new();
}
RuleFor(x => x.ObjectItems).AllElementsOfType(typeof(string));
DateTime validators
BeInFuture
Validates that the date is in the future.
RuleFor(x => x.DateValue).BeInFuture();
BeInPast
Validates that the date is in the past.
RuleFor(x => x.DateValue).BeInPast();
BeLeapYear
Validates that the date is within a leap year.
RuleFor(x => x.DateValue).BeLeapYear();
BeWeekday
Validates that the date falls on a weekday.
RuleFor(x => x.DateValue).BeWeekday();
BeWeekend
Validates that the date falls on a weekend.
RuleFor(x => x.DateValue).BeWeekend();
BeSpecificDayOfWeek
Validates that the date falls on a specified day of the week.
RuleFor(x => x.DateValue).BeSpecificDayOfWeek(DayOfWeek.Monday);
BeWithinRange
Validates that the date is within a specified range.
RuleFor(x => x.DateValue).BeWithinRange(startDate, endDate);
BeSpecificMonth
Validates that the date is in a specific month.
RuleFor(x => x.DateValue).BeSpecificMonth(month);
BeSpecificDay
Validates that the date is on a specific day of the month.
RuleFor(x => x.DateValue).BeSpecificDay(day);
BeExactTimeOfDay
Validates that the date has an exact time of day.
RuleFor(x => x.DateValue).BeExactTimeOfDay(new TimeSpan(hour, minute, second));
IsUtc
Validates that the date is in UTC.
RuleFor(x => x.DateValue).IsUtc();
IsLocalTime
Validates that the date is local time.
RuleFor(x => x.DateValue).IsLocalTime();
URL validators
IsAbsoluteUrl
Validates that the string is a valid absolute URL.
RuleFor(x => x.UrlValue).IsAbsoluteUrl();
IsRelativeUrl
Validates that the string is a valid relative URL.
RuleFor(x => x.UrlValue).IsRelativeUrl();
Acknowledgments
A big shoutout to the original FluentValidation library and its author for creating such a fantastic library. This package is built upon the foundation laid by the original library, and I am very grateful for the inspiration and the work put into it. Thank you!
Support My Work 🌟
If you find this package helpful, consider supporting my work by buying me a coffee ☕!
Your support is greatly appreciated and helps me continue developing and maintaining this project.
You can also give me a ⭐ on github to make my package more relevant to others.
Thank you for your support!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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 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. |
.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 is compatible. |
.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
- FluentValidation (>= 11.8.1)
-
.NETStandard 2.1
- FluentValidation (>= 11.8.1)
-
net5.0
- FluentValidation (>= 11.8.1)
-
net6.0
- FluentValidation (>= 11.8.1)
-
net7.0
- FluentValidation (>= 11.8.1)
-
net8.0
- FluentValidation (>= 11.8.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.