Gleeman.EffectiveValidator
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Gleeman.EffectiveValidator --version 1.0.0
NuGet\Install-Package Gleeman.EffectiveValidator -Version 1.0.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="Gleeman.EffectiveValidator" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Gleeman.EffectiveValidator --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Gleeman.EffectiveValidator, 1.0.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.
// Install Gleeman.EffectiveValidator as a Cake Addin #addin nuget:?package=Gleeman.EffectiveValidator&version=1.0.0 // Install Gleeman.EffectiveValidator as a Cake Tool #tool nuget:?package=Gleeman.EffectiveValidator&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Gleeman Effective Validator
Validation Attributes
Credit Card Validation
[CheckCreditCard(CreditCardType creditCard, string errorMessage)]
Date Validation
[CheckDate(string startDate, string endDate, string errorMessage)]
Email Validation
[CheckEmail(string errorMessage)]
Name Validation
[CheckName(string errorMessage)]
Passport Validation
[CheckPassport(string errorMessage)]
Phone Validation
[CheckPhone(string errorMessage)]
Number Range Validation
[CheckRange(int min, int max, string errorMessage)]
Required Validation
[CheckRequired(string errorMessage)]
String Empty Validation
[CheckStringEmpty(string errorMessage)]
String Lenght Validation
[CheckStringLenght(int minLenght, int maxLenght, string errorMessage)]
Zip Code Validation
[CheckZipCode(string errorMessage)]
How To Use?
public record CreatePersonDto
{
[CheckName("is invalid!")]
[CheckStringLenght(3, 10, "should be between 3 and 10 characters!")]
public string FirstName { get; init; }
[CheckName("is invalid")]
[CheckStringEmpty("should not be empty!")]
public string LastName { get; init; }
[CheckDate("1950/1/1", "2005/1/1", "is invalid!")]
public DateTime DateOfBirth { get; init; }
[CheckRange(18, 73, "is invalid!")]
public int Age { get; init; }
[CheckEmail("is invalid!")]
public string Email { get; init; }
[CheckPhone("is invalid")]
public string PhoneNumber { get; init; }
[CheckPassport("is invalid!")]
public string PassportNumber { get; init; }
[CheckCreditCard(CreditCardType.Visa, "is invalid!")]
public string CreditCartNumber { get; init; }
[CheckZipCode("is invalid!")]
public string ZipCode { get; init; }
[CheckRequired("is required!")]
public bool? IsActive { get; init; }
}
var validator = new EffectiveValidator<CreatePersonDto>();
var validationResult = validator.Validate(createPerson);
if (validationResult.IsValid)
{
using var dbContext = new AppDbContext();
dbContext.Persons.Add(person);
dbContext.SaveChanges();
return Created("", createPerson);
}
return BadRequest(validationResult.ErrorMessages);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.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.