The [Email]
attribute was going to be built into ASP.NET MVC 3 as it was in futures? So is it now available or not? I guess it is quite a dumb question but I\'ve sp
If [Email]
is supposed to be a data annotation for MVC models (like [Required]
), then it's not built into ASP.NET MVC 3.
All the model data annotations are found in the namesace System.ComponentModel.DataAnnotations. There you find classes like RequiredAttribute.
Update:
It's pretty easy to add the Email attribute:
using System.ComponentModel.DataAnnotations;
namespace YourNamespace
{
public class EmailAttribute : RegularExpressionAttribute
{
public EmailAttribute() : base("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")
{
}
}
}
What the best or correct regular expression for checking email addresses is, is a separate and long debate on the net. I'm not insisting that mine is either of it.