How to create custom validation attribute for MVC

You need to register an adapter for the new attribute in order to enable client side validation. Since the RegularExpressionAttribute already has an adapter, which is RegularExpressionAttributeAdapter, all you have to do is reuse it. Use a static constructor to keep all the necessary code within the same class. [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)] … Read more