To keep my model validation clean I would like to implement my own validation attributes, like PhoneNumberAttribute
and EmailAttribute
. Some of these can favorably be be implemented as simple classes that inherit from RegularExpressionAttribute
.
However, I noticed that doing this breaks client side validation of these attributes. I am assuming that there is some kind of type binding that fails somewhere.
Any ideas what I can do to get client side validation working?
Code example:
public sealed class MailAddressAttribute : RegularExpressionAttribute
{
public MailAddressAttribute()
: base(@"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$")
{
}
}