To keep my model validation clean I would like to implement my own validation attributes, like PhoneNumberAttribute
and EmailAttribute
. Some of the
extending of the right answer
public class EmailAttribute : RegularExpressionAttribute
{
static EmailAttribute()
{
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(EmailAttribute), typeof(RegularExpressionAttributeAdapter));
}
public EmailAttribute()
: base(@"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$") //^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$
{
}
}