Atrybut walidacji numeru PESEL oparty o System.ComponentModel.DataAnnotations.
$ dotnet add package PESEL.System.ComponentModel.DataAnnotationsIntegration package providing PESEL number validation using
System.ComponentModel.DataAnnotations.
The package is available on the NuGet Gallery.
Install-Package PESEL.System.ComponentModel.DataAnnotations
Add the Pesel attribute to a model property.
ModelState will be valid only if the PESEL number is valid.
using PESEL.Attributes;
public class Model
{
[Pesel]
public string Pesel { get; set; }
}
var model = new Model
{
Pesel = "02070803628"
};
var context = new ValidationContext(model, null, null);
var validationResults = new List<ValidationResult>();
Assert.IsTrue(
Validator.TryValidateObject(model, context, validationResults, true)
);