数字字符串检查
#region 数字字符串检查 /// <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 = SqlText(retVal, maxLen); if (!IsNumber(retVal)) retVal = string.Empty; } } if (retVal == null) retVal = string.Empty; return retVal; } /// <summary> /// 是否数字字符串 /// </summary> /// <param name="inputData">输入字符串</param> /// <returns></returns> public static bool IsNumber(string inputData) { Match m = RegNumber.Match(inputData); return m.Success; } /// <summary> /// 是否数字字符串可带正负号 /// </summary> /// <param name="inputData">输入字符串</param> /// <returns></returns> public static bool IsNumberSign(string inputData) { Match m = RegNumberSign.Match(inputData); return m.Success; } /// <summary> /// 是否是浮点数 /// </summary> /// <param name="inputData">输入字符串</param> /// <returns></returns> public static bool IsDecimal(string inputData) { Match m = RegDecimal.Match(inputData); return m.Success; } /// <summary> /// 是否是浮点数可带正负号 /// </summary> /// <param name="inputData">输入字符串</param> /// <returns></returns> public static bool IsDecimalSign(string inputData) { Match m = RegDecimalSign.Match(inputData); return m.Success; } #endregion