寂寞的风永不搁浅

学习之初 多为转载 未名出处 敬请见谅 点滴积累 必有作为

博客园 首页 新随笔 联系 订阅 管理
using System;using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Text.RegularExpressions;

/// <summary>
/// CheckRegular 利用正则表达式验证
/// </summary>
public class CheckRegular
{
 public CheckRegular()
 {
  //
  // TODO: 在此处添加构造函数逻辑
  //
 }

  /// <summary>
  /// 检查是否为n位数字
  /// </summary>
  /// <param name="n">数字位数</param>
  /// <param name="parm">需要检查的字符串</param>
  /// <returns>检查结果</returns>
  public static bool CheckNumber(int n,string parmNumber)
  {
  bool result;
  string NumberReg = "^\\d{" + n + "}$";
  result = Regex.IsMatch(parmNumber, NumberReg);
  return result;
  }

  /// <summary>
  /// 至少n位数字
  /// </summary>
  /// <param name="n">数字位数</param>
  /// <param name="parmNumber"></param>
  /// <returns></returns>
  public static bool CheckNumberLeast(int n, string parmNumber)
  {
  bool result;
  string NumberReg = "^\\d{" + n + ",}$";

  result = Regex.IsMatch(parmNumber, NumberReg);
  return result;
  }

  /// <summary>
  /// 检查是否为m-n位数字
  /// </summary>
  /// <param name="m">字符串数字最少位数</param>
  /// <param name="n">字符串数字最多位数</param>
  /// <param name="parmNumber">需要检查的字符串</param>
  /// <returns></returns>
  public static bool CheckNumber(int m,int n, string parmNumber)
  {
  bool result;
  if (m > n)
  {
  int temp;
  temp = m;
  m = n;
  n = temp;
  }
  string NumberReg = "^\\d{" + m + "," + n + "}$";
  result = Regex.IsMatch(parmNumber, NumberReg);
  return result;
  }

  /// <summary>
  /// 检测金额是否正确;规则:数字+"."+数字(最多两位)
  /// </summary>
  /// <param name="n"></param>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckSum(string parmString)
  {
  bool result;
  string sumReg = "^[0-9]*\\.?[0-9]{0,2}$"; ;
  result = Regex.IsMatch(parmString, sumReg);
  return result;
  }

  /// <summary>
  /// 是否只有字幕组成的字符串
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckLetter(string parmString)
  {
  bool result;
  string letterReg = @"^[A-Za-z]+$" ;
  result = Regex.IsMatch(parmString, letterReg);
  return result;
  }

  /// <summary>
  /// 是否又n位字母组成的字符串
  /// </summary>
  /// <param name="n"></param>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckLetter(int n,string parmString)
  {
  bool result;
  string letterReg = @"^[A-Za-z]{" + n + "}$";
  result = Regex.IsMatch(parmString, letterReg);
  return result;
  }

  /// <summary>
  /// 验证m-n位字母组成
  /// </summary>
  /// <param name="m"></param>
  /// <param name="n"></param>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckLetter(int m ,int n, string parmString)
  {
  bool result;
  if (m > n)
  {
  int temp;
  temp = m;
  m = n;
  n = temp;
  }
  string letterReg = @"^[A-Za-z]{" + m + "," + n + "}$";
  result = Regex.IsMatch(parmString, letterReg);
  return result;
  }

  /// <summary>
  /// 检查是否为n位字符,字幕、汉字、数字 都算作一个字符
  /// </summary>
  /// <param name="n">字符位数</param>
  /// <param name="parmString">需要检查的字符串</param>
  /// <returns></returns>
  public static bool CheckString( int n, string parmString)
  {
  bool result;
  string StringReg = "^.{" + n + "}$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 至少n位字符
  /// </summary>
  /// <param name="n">最少字符数</param>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckStringLeast(int n, string parmString)
  {
  bool result;
  string StringReg = "^.{" + n + ",}$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 检查是否为m-n为字符
  /// </summary>
  /// <param name="m">最少字符数</param>
  /// <param name="n">最多字符数</param>
  /// <param name="parmString">需亚检查的字符串</param>
  /// <returns></returns>
  public static bool CheckString(int m, int n, string parmString)
  {
  bool result;
  if (m > n)
  {
  int temp;
  temp = m;
  m = n;
  n = temp;
  }
  string StringReg = "^.{" + m + "," + n + "}$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  #region 身份证号码验证
  /// <summary>
  /// 检查身份证号码是否正确,15位或18位;18位末位可以为x或X
  /// </summary>
  /// <param name="parmIDNumber">需要检查的字符串</param>
  /// <returns></returns>
  public static bool CheckIDNumber(string parmIDNumber)
  {
  bool result;
  string IDNumberReg = "^\\d{15}$|^\\d{17}(?:\\d|x|X)$";
  result = Regex.IsMatch(parmIDNumber, IDNumberReg);
  return result;
  }

  /// <summary>
  /// 验证身份证号,可验证15位或18位 15位补充为18位后验证校验位,18位验证地区、生日、校验位
  /// </summary>
  /// <param name="parmIDNumber"></param>
  /// <returns></returns>
  public static bool CheckIDNumberFull(string parmIDNumber)
  {
  bool result=false;
  string IDNumberReg = "^\\d{15}$|^\\d{17}(?:\\d|x|X)$";
  result = Regex.IsMatch(parmIDNumber, IDNumberReg);
  if(!(result))
  {
  return result;
  }
  if (parmIDNumber.Length == 15)
  {
  parmIDNumber = per15To18(parmIDNumber);
  }
  result = CheckIdNumber18(parmIDNumber);
  return result;
  }
  /// <summary>
  /// 将15位身份证号码转换为18位
  /// </summary>
  /// <param name="perIDSrc"></param>
  /// <returns></returns>
  private static string per15To18(string perIDSrc)
  {
  int iS = 0;
  //加权因子常数 
  int[] iW = new int[] { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 };
  //校验码常数 
  string LastCode = "10X98765432";
  //新身份证号 
  string perIDNew;

  System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^\d{15}$");
  System.Text.RegularExpressions.Match mc = rg.Match(perIDSrc);
  if (!mc.Success)
  {
  return "Error";
  }
  perIDNew = perIDSrc.Substring(0, 6);
  //填在第6位及第7位上填上‘1’,‘9’两个数字 
  perIDNew += "19";

  perIDNew += perIDSrc.Substring(6, 9);

  //进行加权求和 
  for (int i = 0; i < 17; i++)
  {
  iS += int.Parse(perIDNew.Substring(i, 1)) * iW[i];
  }

  //取模运算,得到模值 
  int iY = iS % 11;
  //从LastCode中取得以模为索引号的值,加到身份证的最后一位,即为新身份证号。 
  perIDNew += LastCode.Substring(iY, 1);
  return perIDNew;
  }

  /// <summary>
  /// 检查18为身份证号码是否合法,合法返回"OK";非法则返回非法信息
  /// </summary>
  /// <param name="cid"></param>
  /// <returns></returns>
  public static string CheckIdNumberInfo18(string cid)
  {
  string[] aCity = new string[] { null, null, null, null, null, null, null, null, null, null, null, "北京", "天津", "河北", "山西", "内蒙古", null, null, null, null, null, "辽宁", "吉林", "黑龙江", null, null, null, null, null, null, null, "上海", "江苏", "浙江", "安微", "福建", "江西", "山东", null, null, null, "河南", "湖北", "湖南", "广东", "广西", "海南", null, null, null, "重庆", "四川", "贵州", "云南", "西藏", null, null, null, null, null, null, "陕西", "甘肃", "青海", "宁夏", "新疆", null, null, null, null, null, "台湾", null, null, null, null, null, null, null, null, null, "香港", "澳门", null, null, null, null, null, null, null, null, "国外" };
  double iSum = 0;
  System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^\d{17}(\d|X|x)$");
  System.Text.RegularExpressions.Match mc = rg.Match(cid);
  if (!mc.Success)
  {
  return "位数不正确!";
  }
  cid = cid.ToLower();
  cid = cid.Replace("x", "a");
  if (aCity[int.Parse(cid.Substring(0, 2))] == null)
  {
  return "非法地区";
  }
  try
  {
  DateTime.Parse(cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2));
  }
  catch
  {
  return "非法生日";
  }
  for (int i = 17; i >= 0; i--)
  {
  iSum += (System.Math.Pow(2, i) % 11) * int.Parse(cid[17 - i].ToString(), System.Globalization.NumberStyles.HexNumber);
  }
  if (iSum % 11 != 1)
  {
  return ("非法证号");
  }
  //return (aCity[int.Parse(cid.Substring(0, 2))] + "," + cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2) + "," + (int.Parse(cid.Substring(16, 1)) % 2 == 1 ? "男" : "女"));

  return "OK";
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="cid"></param>
  /// <returns></returns>
  public static bool CheckIdNumber18(string cid)
  {
  string[] aCity = new string[] { null, null, null, null, null, null, null, null, null, null, null, "北京", "天津", "河北", "山西", "内蒙古", null, null, null, null, null, "辽宁", "吉林", "黑龙江", null, null, null, null, null, null, null, "上海", "江苏", "浙江", "安微", "福建", "江西", "山东", null, null, null, "河南", "湖北", "湖南", "广东", "广西", "海南", null, null, null, "重庆", "四川", "贵州", "云南", "西藏", null, null, null, null, null, null, "陕西", "甘肃", "青海", "宁夏", "新疆", null, null, null, null, null, "台湾", null, null, null, null, null, null, null, null, null, "香港", "澳门", null, null, null, null, null, null, null, null, "国外" };
  double iSum = 0;
  System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^\d{17}(\d|X|x)$");
  System.Text.RegularExpressions.Match mc = rg.Match(cid);
  if (!mc.Success)
  {
  return false;
  }
  cid = cid.ToLower();
  cid = cid.Replace("x", "a");
  if (aCity[int.Parse(cid.Substring(0, 2))] == null)
  {
  return false;
  }
  try
  {
  DateTime.Parse(cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2));
  }
  catch
  {
  return false;
  }
  for (int i = 17; i >= 0; i--)
  {
  iSum += (System.Math.Pow(2, i) % 11) * int.Parse(cid[17 - i].ToString(), System.Globalization.NumberStyles.HexNumber);
  }
  if (iSum % 11 != 1)
  {
  return false;
  }
  //return (aCity[int.Parse(cid.Substring(0, 2))] + "," + cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2) + "," + (int.Parse(cid.Substring(16, 1)) % 2 == 1 ? "男" : "女"));

  return true;
  }
#endregion
  /// <summary>
  /// 是否为指定位数,指定字符
  /// </summary>
  /// <param name="n">字符位数</param>
  /// <param name="parmDefinitudeString">指定字符组成的字符串数组</param>
  /// <param name="parmString">需要检查的字符串</param>
  /// <returns></returns>
  public static bool CheckDefinitudeString(int n, string[] parmDefinitudeString, string parmString)
  {
  bool result;
  StringBuilder ss = new StringBuilder(""); 
  for (int i = 0; i < parmDefinitudeString.Length; i++)
  {
  ss = ss.Append(parmDefinitudeString[i]);
  if (i != (parmDefinitudeString.Length - 1))
  {
  ss = ss.Append("|");
  }
  }
  string StringReg = "^[" + ss.ToString() + "]{" + n + "}$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 指定m-n位的制定字符
  /// </summary>
  /// <param name="m">最少匹配次数</param>
  /// <param name="n">最多匹配次数</param>
  /// <param name="parmDefinitudeString">制定字符组成的字符串数组</param>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckDefinitudeString(int m ,int n, string[] parmDefinitudeString, string parmString)
  {
  bool result;
  if (m > n)
  {
  int temp;
  temp = m;
  m = n;
  n = temp;
  }
  StringBuilder ss = new StringBuilder(""); 
  for (int i = 0; i < parmDefinitudeString.Length; i++)
  {
  ss = ss.Append(parmDefinitudeString[i]);
  if (i != (parmDefinitudeString.Length - 1))
  {
  ss = ss.Append("|");
  }
  }
  string StringReg = "^[" + ss.ToString() + "]{" + m + "," + n + "}$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 检查是否为URl
  /// </summary>
  /// <param name="parmString">需要检查字符串</param>
  /// <returns></returns>
  public static bool CheckURL( string parmString)
  {
  bool result;
  string StringReg = "(http(s)?://){0,1}([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 检查是否是正确Email地址
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckEmail(string parmString)
  {
  bool result;
  string StringReg = "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 检查是否为正确邮编号码
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckPostNum(string parmString)
  {
  bool result;
  string StringReg = "\\d{6}";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 是否为正确手机号码;规则:手机号码 13|15(0,3,6,8,9)+8位数字;
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckCellPhone(string parmString)
  {
  bool result;
  string StringReg = @"^(13[0-9]|15[0|3|6|8|9])\d{8}$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 验证是否为正确固定电话号码.规则[3-4位区号+"-"+]7-8位数字[+"-"+0-4位分机号码]
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckImmobilityTel(string parmString)
  {
  bool result;
  string StringReg = @"(^((\d{7,8})|(\d{3,4})-(\d{7,8})|(\d{3,4})-(\d{7,8})-(\d{0,4})|(\d{7,8})-(\d{0,4}))$)";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 验证是否为正确电话号码,包括手机号码,固定电话;规则:手机号码 13|15(0,3,6,8,9)+8位数字;规定电话:规则[3-4位区号+"-"+]7-8位数字[+"-"+0-4位分机号码]
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckTelNumber(string parmString)
  {
  bool result;
  string StringReg = @"^(((13[0-9]|15[0|3|6|8|9])\d{8})|((\d{7,8})|(\d{3,4})-(\d{7,8})|(\d{3,4})-(\d{7,8})-(\d{0,4})|(\d{7,8})-(\d{0,4})))$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 验证年月 规则:"yyyy-mm"
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckYearMonth(string parmString)
  {
  bool result;
  string StringReg = "^\\d{4}-?(?:0[1-9]|1[0-2]|)$";//"^\\d{4}-?(?:0[1-9]|1[0-2]|[1-9])$"可以匹配"yyyy-mm"或"yyyy-m";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 验证日期可验证平年\闰年 规则:"YYYY-[M]M-[D]D" "YYYY/MM/DD" "YYYY_[M]M_[D]D" "YYYY.[M]M.[D]D" 即月份\日期前可有前导0,可无前导0
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckDate(string parmString)
  {
  bool result;
  string StringReg = @"((^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(10|12|0?[13578])([-\/\._])(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(11|0?[469])([-\/\._])(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))([-\/\._])(0?2)([-\/\._])(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)([-\/\._])(0?2)([-\/\._])(29)$)|(^([3579][26]00)([-\/\._])(0?2)([-\/\._])(29)$)|(^([1][89][0][48])([-\/\._])(0?2)([-\/\._])(29)$)|(^([2-9][0-9][0][48])([-\/\._])(0?2)([-\/\._])(29)$)|(^([1][89][2468][048])([-\/\._])(0?2)([-\/\._])(29)$)|(^([2-9][0-9][2468][048])([-\/\._])(0?2)([-\/\._])(29)$)|(^([1][89][13579][26])([-\/\._])(0?2)([-\/\._])(29)$)|(^([2-9][0-9][13579][26])([-\/\._])(0?2)([-\/\._])(29)$))";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 验证日期可验证平年\闰年 规则:"YYYY-MM-DD" 可有无误前导0
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckDateH(string parmString)
  {
  bool result;
  string StringReg = @"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))"; //日期部分
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 验证时间 规则:"HH-MM-SS" 可以有前导0也可以没有前导0
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckTime(string parmString)
  {
  bool result;
  string StringReg = @"^(20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$";  
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 验证日期时间 规则:"YYYY-MM-DD HH-MM-SS" 可有可无前导0 日期与时间中可以有若干空格
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckDateTime(string parmString)
  {
  bool result;
  //string StringReg=@"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$";
  string StringReg = @"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))"; //日期部分
  StringReg += @"(\s*(((0?[0-9])|([1-2][0-3]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$"; //时间部分
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 判断是否是汉字,1个或多个
  /// </summary>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckCharacters(string parmString)
  {
  bool result;
  string StringReg = @"^[\u0391-\uFFE5]+$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 验证n个汉字
  /// </summary>
  /// <param name="n">汉字个数</param>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckCharacters(int n ,string parmString)
  {
  bool result;
  string StringReg = @"^[\u0391-\uFFE5]{" + n + "}$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;
  }

  /// <summary>
  /// 验证m-n个汉字
  /// </summary>
  /// <param name="m">最少汉字个数</param>
  /// <param name="n">最多汉字个数</param>
  /// <param name="parmString"></param>
  /// <returns></returns>
  public static bool CheckCharacters(int m ,int n, string parmString)
  {
  bool result;
  if (m > n)
  {
  int temp;
  temp = m;
  m = n;
  n = temp;
  }
  string StringReg = @"^[\u0391-\uFFE5]{" + m + "," + n + "}$";
  result = Regex.IsMatch(parmString, StringReg);
  return result;

  }

/// <summary>
  /// 函数名称checkparm;检查sql是否有注入的可能性
  /// </summary>
  /// <param name="parm"></param>
  /// <returns></returns>
  public static bool checkparm(string parm)
  {
  //if ((username.ToLower().IndexOf("or") > -1) || (userpwd.ToLower().IndexOf("or") > -1) || (username.ToLower().IndexOf("insert") > -1) || (userpwd.ToLower().IndexOf("insert") > -1) || (username.ToLower().IndexOf("delete") > -1) || (userpwd.ToLower().IndexOf("delete") > -1))
  //{
  // Response.Redirect("index.htm?msg=err01");
  if (parm == null)
  return true;
  if ((parm.ToLower().IndexOf("\"") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("or") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("=") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("'") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf(";") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf(",") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("%") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("exec") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("select") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("count") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("asc") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("char") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("mid") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("insert") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("delete") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("drop") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("update") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("truncate") > -1))
  {
  return false;
  }
  if ((parm.ToLower().IndexOf("from") > -1))
  {
  return false;
  }
  return true;
  }

}


posted on 2008-12-24 15:35  景阳  阅读(550)  评论(0编辑  收藏  举报