• 正則表達式驗證通用方法


    1  string strRegex = @"^\d+$";
        if(!Common.CheckRegx(strRegex,strText))
        {
         MessageBox.Show(this.Page,"請輸入正確庫存數量!");
         return;
        }

    ===========

    2 /// <summary>
      /// 正則表達式驗證通用方法
      /// </summary>
      /// <param name="regex">正則表達式</param>
      /// <param name="str">要驗證的字符</param>
      /// <returns>成功返回true,失敗返回false</returns>
      public static Boolean CheckRegx(string regex,string str)
      {
       System.Text.RegularExpressions.Regex strRegex=new Regex(regex);      
       Match m=strRegex.Match(str);
       if(m.Success)
        return true;
       else
        return false;
      }
      public static Boolean CheckRegx(string regex,string[] str)
      {
       System.Text.RegularExpressions.Regex strRegex=new Regex(regex);      
       int err = 0;
       for(int i=0;i<str.Length;i++)
       {
        Match m=strRegex.Match(str[i]);
        if(!m.Success)
         err++;
       }
       if(err == 0)
        return true;
       else
        return false;
      }

  • 相关阅读:
    SQL语句中case函数
    动态获取数据库表中的字段名
    Java实现最基本的集中排序
    服务器上产看报错的日志的方法
    数据结构顺序表Java实现
    JavaScript创建对象
    JavaScript的基础语法
    javascript介绍
    Java小项目迷你图书管理系统
    CDN——到底用还是不用?
  • 原文地址:https://www.cnblogs.com/csj007523/p/1251114.html
Copyright © 2020-2023  润新知