Exemplo n.º 1
0
        /// <summary>
        /// 检查Request查询字符串的键值,是否是数字,最大长度限制
        /// </summary>
        /// <param name="req">Request</param>
        /// <param name="inputKey">Request的键值</param>
        /// <param name="maxLen">最大长度</param>
        /// <returns>返回Request查询字符串</returns>
        public static string FetchInputDigit(HttpRequest req, string inputKey, int maxLen)
        {
            string retVal = string.Empty;

            if (inputKey != null && inputKey != string.Empty)
            {
                retVal = req.QueryString[inputKey];
                if (null == retVal)
                {
                    retVal = req.Form[inputKey];
                }
                if (null != retVal)
                {
                    retVal = StringHelper.TextSubLength(retVal, maxLen);
                    if (!RegexCheck.IsNumber(retVal))
                    {
                        retVal = string.Empty;
                    }
                }
            }
            if (retVal == null)
            {
                retVal = string.Empty;
            }
            return(retVal);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 验证IP地址是否合法
        /// </summary>
        /// <param name="ip">要验证的IP地址</param>
        public static bool IsIP(string ip)
        {
            //如果为空,认为验证合格
            if (IsNullOrEmpty(ip))
            {
                return(true);
            }

            //清除要验证字符串中的空格
            ip = ip.Trim();

            //模式字符串
            string pattern = @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$";

            //验证
            return(RegexCheck.IsMatch(ip, pattern));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 验证是否为整数 如果为空,认为验证不合格 返回false
        /// </summary>
        /// <param name="number">要验证的整数</param>
        public static bool IsInt(string number)
        {
            //如果为空,认为验证不合格
            if (IsNullOrEmpty(number))
            {
                return(false);
            }

            //清除要验证字符串中的空格
            number = number.Trim();

            //模式字符串
            string pattern = @"^[0-9]+[0-9]*$";

            //验证
            return(RegexCheck.IsMatch(number, pattern));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 返回客户端浏览器版本
        /// 如果是IE类型,返回版本数字
        /// 如果不是IE类型,返回-1
        /// </summary>
        /// <returns>一位数字版本号</returns>
        public static int GetClientBrowserVersion()
        {
            string USER_AGENT = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"];

            if (USER_AGENT.IndexOf("MSIE") < 0)
            {
                return(-1);
            }

            string version = USER_AGENT.Substring(USER_AGENT.IndexOf("MSIE") + 5, 1);

            if (!RegexCheck.IsInt(version))
            {
                return(-1);
            }

            return(Convert.ToInt32(version));
        }