SmartValidationsLibrary 2.1.0
dotnet add package SmartValidationsLibrary --version 2.1.0
NuGet\Install-Package SmartValidationsLibrary -Version 2.1.0
<PackageReference Include="SmartValidationsLibrary" Version="2.1.0" />
<PackageVersion Include="SmartValidationsLibrary" Version="2.1.0" />
<PackageReference Include="SmartValidationsLibrary" />
paket add SmartValidationsLibrary --version 2.1.0
#r "nuget: SmartValidationsLibrary, 2.1.0"
#:package SmartValidationsLibrary@2.1.0
#addin nuget:?package=SmartValidationsLibrary&version=2.1.0
#tool nuget:?package=SmartValidationsLibrary&version=2.1.0
Smart Validations Library
SmartValidationsLibrary is a lightweight, non-throwing C# validation library. Every check returns a ValidationResult (IsValid + ErrorMessage) instead of an exception, and every validation also ships as an attribute so you can validate a whole object's properties in one call.
Features
- Email —
IsValidEmail/[EmailValidation] - Phone number, region-aware (USA, UK, Spain, Ireland) —
IsValidPhoneNumber/[PhoneNumberValidation(Region.Spain)] - Postal code, region-aware (USA, UK, Spain, Ireland) —
IsValidPostalCode/[PostalCodeValidation(Region.Spain)] - Date —
IsValidDate - URL (http/https) —
IsValidUrl/[UrlValidation] - Credit card number (Luhn checksum) —
IsValidCreditCardNumber/[CreditCardValidation] - Password strength, configurable —
IsValidPassword/[PasswordValidation] - IP address (IPv4/IPv6) —
IsValidIPAddress/[IPAddressValidation] - Numeric range —
IsInRange/[RangeValidation(min, max)] - String length —
IsValidLength/[LengthValidation(min, max)] - Custom rules — register your own regex via
AddCustomValidation, thenIsValidCustom/[CustomValidation("name")] - Entity validation —
EntityValidator.ValidateEntity<T>collects every failing property on an object, not just the first one
Installation
dotnet add package SmartValidationsLibrary
Usage
Standalone checks
using SmartValidationsLibrary;
var result = Validator.IsValidEmail("user@example.com");
if (!result.IsValid)
Console.WriteLine(result.ErrorMessage);
Validator.IsValidPhoneNumber("612345678", Region.Spain);
Validator.IsValidPostalCode("28001", Region.Spain);
Validator.IsValidDate("2026-01-15");
Validator.IsValidUrl("https://example.com");
Validator.IsValidCreditCardNumber("4111 1111 1111 1111");
Validator.IsValidPassword("Str0ng!Pass");
Validator.IsValidIPAddress("192.168.1.1");
Validator.IsInRange(5, 1, 10);
Validator.IsValidLength("hello", 1, 10);
Validator.AddCustomValidation("digits-only", @"^\d+$");
Validator.IsValidCustom("12345", "digits-only");
Entity validation with attributes
using SmartValidationsLibrary;
public class SignupRequest
{
[EmailValidation]
public string Email { get; set; } = string.Empty;
[PhoneNumberValidation(Region.Spain)]
public string Phone { get; set; } = string.Empty;
[PasswordValidation(minLength: 8)]
public string Password { get; set; } = string.Empty;
[LengthValidation(2, 50)]
public string DisplayName { get; set; } = string.Empty;
}
var errors = EntityValidator.ValidateEntity(signupRequest);
// errors is empty when everything is valid, otherwise contains
// one ValidationResult per failing property (PropertyName + ErrorMessage).
Requirements
- .NET 8.0, 9.0, or 10.0
Development
Want to contribute? Great!
git clone https://github.com/AdrianBailador/SmartValidationsLibrary.git
cd SmartValidationsLibrary
dotnet test
Please include tests for any new functionality.
License
MIT — see LICENSE.
| Product | Versions 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 is compatible. 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. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Now multi-targets net8.0, net9.0, and net10.0 (was net10.0-only). Same 2.0.0 rewrite otherwise: fixed IsValidEmail throwing RegexParseException on every call due to invalid character-class syntax in the email pattern, fixed two conflicting EntityValidator implementations existing side by side (consolidated into one that collects every validation error), fixed the UK phone number regex rejecting real numbers, and added IsValidPostalCode, IsValidUrl, IsValidCreditCardNumber, IsValidPassword, IsValidIPAddress, IsInRange, and IsValidLength, each with a matching validation attribute.