3 Open-Source Validation Projects for ASP.NET MVC

The goal of this post is to show you validation options beyond those that come in-the-box from Microsoft and the ASP.NET team.

Currently, there are nine pre-built validation attributes that come with MVC:

hierarchy

While these are very helpful, knowing where to look to find additional validation options is super helpful. For example, what if the State property is only supposed to be required if Country property is set to USA? Good luck with that one!

So in this post, I will point you at a few open-source DataAnnotation libraries built for MVC.

The first to check is FoolProof:

http://foolproof.codeplex.com/

Jump over there and browse through the various attributes available. There are a bunch, such as RequiredIfTrue. Like so many things with ASP.NET MVC, the way to add foolproof to your project is to use NuGet. Just fire it up and search for FoolProof:

nuget-foolproof

Foolproof is great for dependent validation scenarios such as this field is required if that field is checked or something like that.

Next up, DataAnnotationsExtensions:

http://dataannotationsextensions.org/

DataAnnotationsExtensions is a nice one as well. This library is focused more on validating certain data types: credit cards, dates, urls, etc. Again, it’s available from NuGet. This time you probably want to reference DataAnnotationsExtensions.MVC3 rather than the base project.

Finally, let’s look at Moon.Validation:

http://git.mooncode.net/moon.validation

Look at the files there that end in “Attribute”. Again, there are some nice, dependent validation attributes here.

I hope that gives you a sense of what’s out there beyond just the built-in validation options. I’m sure there are a bunch of projects that I missed. If you know of any, add a comment with a link and why you like it!

Cheers,
@mkennedy

6 comments

Submit a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s