123456789101112131415161718192021222324252627282930313233343536 |
- 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]+$";
- public EmailAttribute()
- {
- this.ErrorMessage = "邮箱格式不正确";
- }
- //重写基类方法
- 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;
- }
- }
- }
|