Update 8: The question has a new title ,hopefully it will help other avoid time consuming bugs...
I have the following code: (You need a reference t
DO NOT extend RegularExpressionAttribute and set AllowMultiple to true
It will bring you nothing but trouble.
You can create 2 distinct attributes that inherit from RegularExpressionAttribute.
public class MyModel
{
[MultipleRegExAttribute2(@"[^?.]{1,100}$")]
[MultipleRegExAttribute3(@"^((?![><&])[\s\S])*$")]
public string Name { get; set; }
}
public class MultipleRegExAttribute2 : RegularExpressionAttribute
{
public MultipleRegExAttribute2(string pattern) : base(pattern) { }
}
public class MultipleRegExAttribute3 : RegularExpressionAttribute
{
public MultipleRegExAttribute3(string pattern) : base(pattern) { }
}
A friend of mine showed me the root of the problem.
I have to override the TypeId property.
See this question:Custom validation attribute with multiple instances problem
and this article :The Importance of TypeId in ASP.NET MVC DataAnnotations Validation Attributes