123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.ComponentModel.DataAnnotations;
- using System.Text.RegularExpressions;
- using System.Globalization;
- namespace EMIS.ViewModel
- {
- public sealed class EmailAttribute : ValidationAttribute
- {
- public const string reg = @"^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]+$";
- /// <summary>
- ///
- /// </summary>
- public EmailAttribute()
- {
- this.ErrorMessage = "邮箱格式不正确";
- }
- /// <summary>
- /// 重写基类方法
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public override bool IsValid(object value)
- {
- if (value == null)
- return true;
- if (value is string)
- {
- Regex regEx = new Regex(reg);
- return regEx.IsMatch(value.ToString());
- }
- return false;
- }
- }
- }
|