自定义Metadata验证属性

一、定义


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; }
posted @ 2019-12-22 16:57  秋飘  阅读(234)  评论(0编辑  收藏  举报