RecordValidator 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package RecordValidator --version 1.0.2                
NuGet\Install-Package RecordValidator -Version 1.0.2                
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="RecordValidator" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add RecordValidator --version 1.0.2                
#r "nuget: RecordValidator, 1.0.2"                
#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 RecordValidator as a Cake Addin
#addin nuget:?package=RecordValidator&version=1.0.2

// Install RecordValidator as a Cake Tool
#tool nuget:?package=RecordValidator&version=1.0.2                

RecordValidator

RecordValidator is a .NET library for validating records against predefined rules.

Installation

You can install RecordValidator via NuGet Package Manager Console by running:

Install-Package RecordValidator

Or, you can install it using the .NET CLI:

dotnet add package RecordValidator

Define the rule for the properties for the class

public class Employee
    {
        [Mandatory("Id cannot be 0",validateForDefaultValue:true)]
        public int id { get; set; }
        [Mandatory]
        public string name { get; set; }
        [Mandatory]
        public int age { get; set; }
        [Mandatory(validateForDefaultValue:true)]
        public decimal Salary { get; set; }
        [Mandatory(validateForDefaultValue:true)]
        public char Gender { get; set; }
        [Date(minDate: "1995-01-01",maxDate: "2004-01-01", errorMessage:"Min date and max date should be satified")]
        public DateTime Dob { get; set; }
        [Date(minDate: "2004-01-01")]
        public string JoiningDate { get; set; }
        [Email]
        public string EmailId { get; set; }

    }

Now call the ValidateValueAndThrowException function

try
{
    var empolyee = new Employee()
    {
        Name = "",
        age =28,
        Salary=20000,
        Gender='M',
        Dob=new DateTime(1995, 01, 02)
        JoiningDate="2019-01-01"
        Email="vpathak154gmail.com",
        Id = 1,
        EmailId="Vpathak154@gmail.com"
    };
    empolyee.ValidateValueAndThrowException();
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

New Changes in 1.0.2

  • Regular Expression is added for miscellaneous validations.
public class Employee
    {
        public int Id {get;set;}
        [Mandatory]
        [RegularExpression(pattern: "^(?:(?:\+|0{0,2})91(\s*[\-]\s*)?|[0]?)?[6789]\d{9}$",errorMessage:"Please enter indian mobile number")]
        public string MobileNumber {get;set;}
    }

Features

  • Support for various validation rules and will be added more in coming versions.
  • Easy to add in the project and can be easily added in existing project.
  • Custom error message can be set if not given then default will be taken.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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.  net9.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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.

Version Downloads Last updated
2.0.0 89 1/5/2025
1.5.0 135 7/6/2024
1.4.0 120 6/15/2024
1.3.0 103 6/9/2024
1.2.0 99 5/20/2024
1.1.0 142 5/5/2024
1.0.2 82 5/2/2024
1.0.1 116 4/27/2024
1.0.0 116 4/21/2024