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}$")
{
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…