TNValidate is now open source

TNValidate is now open source

Our internal validation library TNValidate is now available as a project on GitHub. We released this as open source because we wanted to let others take part in our internal libraries. The library is written in C# and uses a “Fluent Interface” to define the validation rules.

By using TNValidate, we have achieved a uniform way to write our validation logic, which in turn has reduced the number of bugs and made our code more readable.

Using TNValidate is very simple:

// Instantiate validator.
var Validate = new Validator(ValidationLanguageEnum.English);

// Basic validation.
Validate.That(Email, "Email address").IsEmail();

// Chaining a couple of rules.
Validate.That(Name, "Name").IsLongerThan(3).IsShorterThan(100);

// Supply a custom error message.
Validate.That(Age, "Age").IsGreaterThanOrEqual(13,
"You must be older than 13 to sign up");

// Check if validation succeeded.
if (Validate.HasErrors())
{
// Show errors (Validate.ValidatorResults can be data-bound).
foreach (var Error in Validate.ValidatorResults)
Console.WriteLine(Error.ValidationMessage);
}
else
{
// Was fine, continue...
// ...
}

Head over to GitHub and give it a try!

Share This Story

Related Posts

About Tore Nestenius - Freelance software development instructor and consultant.

About me

My name is Tore Nestenius and I’m a trainer and senior software developer focusing on Architecture, Security and Identity, .NET, C#, Backend, and Cloud, among other things.

Do You Want Tore To Be Your Mentor?

Categories