Exemple #1
0
        /// <summary>
        /// 验证邮箱是否合法
        /// </summary>
        /// <param name="mailAddress"></param>
        /// <returns></returns>
        public static OperationResult ValidateEmail(string mailAddress)
        {
            string strRegex;
            Regex  reg;

            strRegex = @"^[a-zA-Z0-9][a-zA-Z0-9_\-\.]*@((\[[0-9]{1,3}" + @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            // Regex reg = new Regex("^[a-zA-Z0-9_-]+@([a-zA-Z0-9-]+\\.){1,}(com|net|edu|miz|biz|cn|cc)$");

            reg = new Regex(strRegex);

            if (!reg.IsMatch(mailAddress))
            {
                return(OperationResultUtil.CreateErrorResult(""));
            }

            strRegex = @"^.{6,}$";

            reg = new Regex(strRegex);

            if (!reg.IsMatch(mailAddress))
            {
                return(OperationResultUtil.CreateErrorResult("邮箱不合法"));
            }

            OperationResult operationResult = CheckDirtyWords(mailAddress);

            if (operationResult.State != OperationResultUtil.StateSuccess)
            {
                return(operationResult);
            }

            return(OperationResultUtil.CreateSuccessResult("邮箱合法"));
        }
Exemple #2
0
        /// <summary>
        /// 验证用户名
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static OperationResult ValidateUserName(string userName)
        {
            string strRegex;
            Regex  reg;

            strRegex = @"^[^\s]*$";
            reg      = new Regex(strRegex);

            if (!reg.IsMatch(userName))
            {
                return(OperationResultUtil.CreateErrorResult("用户名"));
            }

            strRegex = @"^[a-zA-Z0-9_\u4e00-\u9fa5]+$";
            reg      = new Regex(strRegex);

            if (!reg.IsMatch(userName))
            {
                return(OperationResultUtil.CreateErrorResult("用户名"));
            }

            OperationResult operationResult = CheckDirtyWords(userName);

            if (operationResult.State != OperationResultUtil.StateSuccess)
            {
                return(operationResult);
            }

            //键入的字符个数是否<4
            //若是,则提交创建申请后提示:您的Username长度过短,请输入4-20个字符的Username。
            strRegex = @"^[^\s]{4,}$";
            reg      = new Regex(strRegex);

            if (!reg.IsMatch(userName))
            {
                return(OperationResultUtil.CreateErrorResult("提示的信息"));
            }

            //键入的字符个数是否>20
            //若是,则提交创建申请后提示:您的Username长度过长,请输入4-20个字符的Username。
            strRegex = @"^[^\s]{4,20}$";
            reg      = new Regex(strRegex);

            if (!reg.IsMatch(userName))
            {
                return(OperationResultUtil.CreateErrorResult("提示的信息"));
            }

            return(OperationResultUtil.CreateSuccessResult("提示的信息"));
        }
Exemple #3
0
        /// <summary>
        /// 检查是否含有屏蔽词
        /// </summary>
        /// <param name="inputWords"></param>
        /// <returns></returns>
        private static OperationResult CheckDirtyWords(string inputWords)
        {
            //键入字符是否含有非法字符(WPT屏蔽词+联众屏蔽词)
            //WPT屏蔽词库需要Hong提供
            //联众屏蔽词库由平台技术部廖腾负责维护
            IEnumerable <string> wptWordBlockList = ReadWPTWordBlockList();
            IEnumerable <string> ourgameBlockList = ReadOurgameWordBlockList();

            //wpt屏蔽词
            if (wptWordBlockList.Any(wpt => inputWords.IndexOf(" " + wpt, System.StringComparison.Ordinal) >= 0) || wptWordBlockList.Any(wpt => inputWords.IndexOf(wpt + " ", System.StringComparison.Ordinal) >= 0))
            {
                return(OperationResultUtil.CreateErrorResult("提示的信息"));
            }

            //联众屏蔽词
            if (ourgameBlockList.Any(ourgame => inputWords.IndexOf(ourgame, System.StringComparison.Ordinal) >= 0))
            {
                return(OperationResultUtil.CreateErrorResult("提示的信息"));
            }

            return(OperationResultUtil.CreateSuccessResult(""));
        }
Exemple #4
0
        /// <summary>
        /// 验证密码是否合法
        /// </summary>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public static OperationResult ValidatePassword(string pwd)
        {
            string strRegex;
            Regex  reg;

            strRegex = @"^[^,;']+$";
            reg      = new Regex(strRegex);

            if (!reg.IsMatch(pwd))
            {
                return(OperationResultUtil.CreateErrorResult("密码合法"));
            }

            strRegex = @"^[^,;']{6,16}$";
            reg      = new Regex(strRegex);

            if (!reg.IsMatch(pwd))
            {
                return(OperationResultUtil.CreateErrorResult("太短"));
            }

            return(OperationResultUtil.CreateSuccessResult("成功"));
        }