一、定义
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.DataAnnotations; namespace HJ.BaseMetadata { /// <summary> /// 邮箱验证类 /// </summary> public class EmailAttribute :RegularExpressionAttribute { //验证邮箱 public EmailAttribute():base(@"^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$") { } } }
二、调用
[Email(ErrorMessage="邮箱格式不正确")))] public string Email { get; set; }