Пример #1
0
        /// <summary>
        /// 校验登录密码
        /// </summary>
        /// <param name="pwd">需要进行校验的密码字符串</param>
        /// <returns>返回校验结果</returns>
        public static ValidResult IsStrongPassword(string pwd)
        {
            //如果密码字符串空校验通过
            if (StringValid.IsEmpty(pwd))
            {
                //密码长度必须在6~20位之间
                if (pwd.Length < 6 || pwd.Length > 20)
                {
                    return(new ValidResult(false, ValidFailCode.WrongLength, "密码长度必须在6-20位"));
                }

                //密码不能包含中文正则校验
                if (new Regex(@"[\u4e00-\u9fa5]").IsMatch(pwd))
                {
                    return(new ValidResult(false, ValidFailCode.WrongFormat, "不能包含中文"));
                }

                //密码不能为纯数字或字母校验
                if (new Regex(@"^([0-9]+|[a-zA-Z]+)$").IsMatch(pwd))
                {
                    return(new ValidResult(false, ValidFailCode.WrongFormat, "密码不能为纯数字或纯字母"));
                }
                return(ValidResult.Success);
            }
            else
            {
                return(new ValidResult(false, ValidFailCode.IsNullOrWhiteSpace, "密码不能为空"));
            }
        }
Пример #2
0
        /// <summary>
        /// 校验是否是正确的手机号码
        /// </summary>
        /// <param name="mobile">需要校验的手机号码</param>
        /// <returns>返回校验结果</returns>
        public static ValidResult IsMobile(string mobile)
        {
            //检查是否为空
            var strCheck = StringValid.IsEmpty(mobile);

            if (strCheck)
            {
                //检查是否符合正则格式
                var regex = new Regex(@"^1[3-9]\d{9}$");
                if (regex.IsMatch(mobile))
                {
                    return(ValidResult.Success);
                }
                else
                {
                    return(new ValidResult(false, ValidFailCode.WrongFormat, "手机格式错误"));
                }
            }
            else
            {
                return(strCheck.WithMessage("手机号为空"));
            }
        }