The Gu provides an example of how you might create a custom validator that overrides RegularExpressionAttribute (http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx).
The advantage of this is that you don't have to create a custom Model Validator (http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx).
But I can't get it to work.
Given the following code:
public class NameAttribute : RegularExpressionAttribute {
public NameAttribute()
: base(@"^[\w\s\-\']+$") {
}
}
This works:
[RegularExpression(@"^[\w\s\-\']+$")]
But this doesn't:
[Name]
Have I misunderstood an aspect of Scott's example or is the example flawed in that MVC doesn't support derived types out of the box, so actually I will have to create a a corresponding ModelValidator?