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

4 thoughts on “3 Open-Source Validation Projects for ASP.NET MVC

  1. Pingback: Dew Drop – January 17, 2013 (#1,481) | Alvin Ashcraft's Morning Dew

  2. if you need RequiredIf or similar attributes, then use this http://git.mooncode.net/moon.validation, since it’s stll a living project.

    I also hope, they extend the library with a HideIf atribute according to my specification – this could help a lot when creating UI without the need to add jquery plumbing only to hide a div when a value changes… If you think this attribute is usefull, just ask the author of the moon.validator to include it in the next release :D

Leave a Reply

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 )

Google+ photo

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

Connecting to %s