Please post questions and issues on Github:




NValidator is a lightweight extensible validation library for .NET that support fluent syntax. The implementation and fluent syntax are inspired from the well-known library Fluent Validation. However, I implemented it using Chain of Reponsibility pattern and made it fully support Dependency Injection for validator classes.

Here is a simple example that can help you to start:

    public class UserValidator : TypeValidator<User>
        public UserValidator()
            RuleFor(user => user.Id)

            RuleFor(user => user.UserName)
                .Length(6, 10)
                .Must(x => !x.Contains(" ")).WithMessage("@PropertyName cannot contain empty string.");

            RuleFor(user => user.Password)
                .Length(6, 20)
                .Must(x => x.Any(c => c >= 'a' && c <= 'z') &&
                           x.Any(c => c >= '0' && c <= '9') &&
                           x.Any(c => c >= 'A' && c <= 'Z')).WithMessage("@PropertyName must contain both letter and digit.");

            RuleFor(user => user.Title)
                .In("MR", "MS", "MRS", "DR", "PROF", "REV", "OTHER");

            RuleFor(user => user.FirstName)
                .NotEmpty().WithMessage("Please specify the first name.");

            RuleFor(user => user.LastName)
                .NotEmpty().WithMessage("Please specify the last name.");
            RuleFor(user => user.Email)

            RuleFor(user => user.Address)
                .When(x => x != null);

The source code repository for this project is on GitHub. The NuGet package "NValidator" is also available.

Please checkout the document and other topics to get started.

Last edited Aug 20, 2014 at 11:17 AM by nvthoai, version 8