身份证号验证

public class ValidateIdNum

    {        #region 验证身份证  
        public static bool CheckIDCard(string Id)
        {            if (string.IsNullOrWhiteSpace(Id))                return false;            if (Id.Length == 18)
            {                bool check = CheckIDCard18(Id);                return check;
            }            else if (Id.Length == 15)
            {                bool check = CheckIDCard15(Id);                return check;
            }            else
            {                return false;
            }
        }        private static bool CheckIDCard18(string Id)
        {            long n = 0;            if (long.TryParse(Id.Remove(17), out n) == false || n 

[AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]    public class IdNumberAttribute : ValidationAttribute
    {        public override bool IsValid(object value)
        {            if (value == null)
            {                return false;
            }            string text = value as string;            return ValidateIdNum.CheckIDCard(text);
        }

    }


下一篇: C#软件授权、注册、加密、解密模块源码解析并制作注册机生成license