123456789101112131415161718192021 |
- using System;
- using System.ComponentModel.DataAnnotations;
- using System.Text.RegularExpressions;
- namespace GxPress.Common.Validation
- {
- [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
- public class MobileAttribute : ValidationAttribute
- {
- public override bool IsValid(object value)
- {
- return Regex.IsMatch(value.ToString(), @"^1[3456789]\d{9}$", RegexOptions.IgnoreCase);
- }
- public override string FormatErrorMessage(string name)
- {
- return "不是合法的手机号";
- }
- }
- }
|