网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 设计资源 > .Net编程 > 正文

C#常用数据检查类

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务
  1. using System; 
  2. using System.Text; 
  3. using System.Web; 
  4. using System.Web.UI.WebControls; 
  5. using System.Text.RegularExpressions; 
  6. namespace Legalsoft.Wizard.Basic // 设置项目属性可修改本项目的命名空间   
  7.     /// <summary>   
  8.     /// 页面数据校验类   
  9.     /// 修改自 李天平先生的作品,一并感谢。   
  10.     /// </summary>   
  11.     public class PageValidate 
  12.     { 
  13.         private static Regex RegNumber = new Regex("^[0-9]+contentquot;); 
  14.         private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+contentquot;); 
  15.         private static Regex RegDecimal = new Regex("^[0-9]+[.]?[0-9]+contentquot;); 
  16.         //等价于^[+-]?\d+[.]?\d+contentnbsp;  
  17.         private static Regex RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+contentquot;); 
  18.         //w 英文字母或数字的字符串,和 [a- zA-Z0-9] 语法一样    
  19.         private static Regex RegEmail = new Regex("^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)contentquot;); 
  20.         private static Regex RegCHZN = new Regex("[\u4e00-\u9fa5]"); 
  21.         public PageValidate() 
  22.         { 
  23.         } 
  24.         #region 数字字符串检 查 
  25.         /// <summary>   
  26.         /// 检查Request查询字符串的键值,是 否是数字,最大长度限制   
  27.         /// </summary>   
  28.         /// <param name="req">Request</param>   
  29.         /// <param name="inputKey"& gt;Request的键值</param>   
  30.         /// <param name="maxLen"& gt;最大长度</param>   
  31.         /// <returns>返回Request查询字符串</returns>   
  32.         public static string IsDigit(HttpRequest req, string inputKey, int maxLen) 
  33.         { 
  34.             string retVal = string.Empty; 
  35.             if (inputKey != null && inputKey != string.Empty) 
  36.             { 
  37.                 retVal = req.QueryString[inputKey]; 
  38.                 if (null == retVal) 
  39.                     retVal = req.Form[inputKey]; 
  40.                 if (null != retVal) 
  41.                 { 
  42.                     retVal = SqlText(retVal, maxLen); 
  43.                     if (!IsNumber(retVal)) 
  44.                         retVal = string.Empty; 
  45.                 } 
  46.             } 
  47.             if (retVal == null
  48.                 retVal = string.Empty; 
  49.             return retVal; 
  50.         } 
  51.         /// <summary>   
  52.         /// 是否数字字符串   
  53.         /// </summary>   
  54.         /// <param name="inputData"& gt;输入字符串</param>   
  55.         /// <returns></returns>   
  56.         public static bool IsNumber(string inputData) 
  57.         { 
  58.             Match m = RegNumber.Match(inputData); 
  59.             return m.Success; 
  60.         } 
  61.         /// <summary>   
  62.         /// 是否数字字符串 可带正负号   
  63.         /// </summary>   
  64.         /// <param name="inputData"& gt;输入字符串</param>   
  65.         /// <returns></returns>   
  66.         public static bool IsNumberSign(string inputData) 
  67.         { 
  68.             Match m = RegNumberSign.Match(inputData); 
  69.             return m.Success; 
  70.         } 
  71.         /// <summary>   
  72.         /// 是否是浮点数   
  73.         /// </summary>   
  74.         /// <param name="inputData"& gt;输入字符串</param>   
  75.         /// <returns></returns>   
  76.         public static bool IsDecimal(string inputData) 
  77.         { 
  78.             Match m = RegDecimal.Match(inputData); 
  79.             return m.Success; 
  80.         } 
  81.         /// <summary>   
  82.         /// 是否是浮点数 可带正负号   
  83.         /// </summary>   
  84.         /// <param name="inputData"& gt;输入字符串</param>   
  85.         /// <returns></returns>   
  86.         public static bool IsDecimalSign(string inputData) 
  87.         { 
  88.             Match m = RegDecimalSign.Match(inputData); 
  89.             return m.Success; 
  90.         } 
  91.         #endregion 
  92.         #region 中文检测 
  93.         /// <summary>   
  94.         /// 检测是否有中文字符   
  95.         /// </summary>   
  96.         /// <param name="inputData"></param>   
  97.         /// <returns></returns>   
  98.         public static bool IsHasCHZN(string inputData) 
  99.         { 
  100.             Match m = RegCHZN.Match(inputData); 
  101.             return m.Success; 
  102.         } 
  103.         #endregion 
  104.         #region 邮件地址 
  105.         /// <summary>   
  106.         /// 是否是浮点数 可带正负号   
  107.         /// </summary>   
  108.         /// <param name="inputData"& gt;输入字符串</param>   
  109.         /// <returns></returns>   
  110.         public static bool IsEmail(string inputData) 
  111.         { 
  112.             Match m = RegEmail.Match(inputData); 
  113.             return m.Success; 
  114.         } 
  115.         #endregion 
  116.         #region 其他 
  117.         /// <summary>   
  118.         /// 检查字符串最大长度,返回指定长度的串   
  119.         /// </summary>   
  120.         /// <param name="sqlInput"& gt;输入字符串</param>   
  121.         /// <param name="maxLength">最大长度</param>   
  122.         /// <returns></returns>            
  123.         public static string SqlText(string sqlInput, int maxLength) 
  124.         { 
  125.             if (sqlInput != null && sqlInput != string.Empty) 
  126.             { 
  127.                 sqlInput = sqlInput.Trim(); 
  128.                 if (sqlInput.Length > maxLength)//按最大长度截取字符串   
  129.                     sqlInput = sqlInput.Substring(0, maxLength); 
  130.             } 
  131.             return sqlInput; 
  132.         } 
  133.         /// <summary>   
  134.         /// 字符串编码   
  135.         /// </summary>   
  136.         /// <param name="inputData"></param>   
  137.         /// <returns></returns>   
  138.         public static string HtmlEncode(string inputData) 
  139.         { 
  140.             return HttpUtility.HtmlEncode(inputData); 
  141.         } 
  142.         /// <summary>   
  143.         /// 设置Label显示Encode的字符串   
  144.         /// </summary>   
  145.         /// <param name="lbl"></param>   
  146.         /// <param name="txtInput"></param>   
  147.         public static void SetLabel(Label lbl, string txtInput) 
  148.         { 
  149.             lbl.Text = HtmlEncode(txtInput); 
  150.         } 
  151.         public static void SetLabel(Label lbl, object inputObj) 
  152.         { 
  153.             SetLabel(lbl, inputObj.ToString()); 
  154.         } 
  155.         #endregion 
  156.     } 
  • 上一篇资讯: 用C#读写文件的方法
  • 设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
    版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师