当前位置: 首页>>代码示例>>C#>>正文


C# Regex.IsMatch方法代码示例

本文整理汇总了C#中Regex.IsMatch方法的典型用法代码示例。如果您正苦于以下问题:C# Regex.IsMatch方法的具体用法?C# Regex.IsMatch怎么用?C# Regex.IsMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Regex的用法示例。


在下文中一共展示了Regex.IsMatch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Button1_Click

    //查询用户
    protected void Button1_Click(object sender, EventArgs e)
    {
        //输入异常检查
        string strIn = TextBox1.Text.Trim();
        //有点问题,数字挂字母??
        Regex r=new Regex(@"\d{1,100}");
        if(r.IsMatch(strIn) & (strIn.Length<5|strIn.Length>6))
        {
            if (Session["lang"].ToString() == "zh-cn")
                Response.Write("<script>alert('PSID的长度必须是5或者6!');window.location.href='./Query_employee.aspx'</script>");
            else
                Response.Write("<script>alert('The length of PSID must be 5 or 6!');window.location.href='./Query_employee.aspx'</script>");
            return;
        }

        Query qr = new Query();
        DataTable dt = new DataTable();
        DataTable dtEmployeeExist = new DataTable();
        //Query by PSID or Name
        if (r.IsMatch(strIn))
        {
            dt = qr.QueryByPSID(strIn);
            Session["PSID"] = strIn;
            dtEmployeeExist = qr.GetEmployeeByPSID(strIn);
        }
        else
        {
            dt = qr.QueryByName(strIn);
            Operation op = new Operation();
            Session["PSID"] = op.NameToPSID(strIn);
            dtEmployeeExist = qr.GetEmployeeByName(strIn);
        }

        //该employee不存在的处理
        if (dtEmployeeExist.Rows.Count == 0)
        {
            if (Session["lang"].ToString() == "zh-cn")
                Response.Write("<script>alert('" + TextBox1.Text.Trim() + " 不存在!');window.location.href='./Query_employee.aspx'</script>");
            else
                Response.Write("<script>alert('" + TextBox1.Text.Trim() + " does not exist!');window.location.href='./Query_employee.aspx'</script>");
            return;
        }

        //有该employee,但借阅记录为空的处理
        if (dt.Rows.Count == 0)
        {
            if (Session["lang"].ToString() == "zh-cn")
                Response.Write("<script>alert('" + TextBox1.Text.Trim() + " 没有借阅任何图书!');window.location.href='./Query_employee.aspx'</script>");
            else
                Response.Write("<script>alert('" + TextBox1.Text.Trim() + " did not borrow any book!');window.location.href='./Query_employee.aspx'</script>");
            return;
        }

        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
开发者ID:runwithwind,项目名称:mini_project_BMS,代码行数:57,代码来源:Query_employee.aspx.cs

示例2: Main

    public static void Main()
    {
        Regex r1 = new Regex(@"<([^>]+)>[^<]*</(\1)>");
        string s0 = "<M>S</M>";
        string s1 = "<M>S</I>";

        Console.WriteLine(r1.IsMatch(s0));
        Console.WriteLine(r1.IsMatch(s1));

        Console.WriteLine("Press any key to continue...");
        Console.ReadKey();
    }
开发者ID:dbremner,项目名称:hycs,代码行数:12,代码来源:xmltag.cs

示例3: IsValidName

    private static bool IsValidName(string[] names)
    {
        bool isValid = true;

        Regex namePattern = new Regex("[A-Z][a-z]+");

        if (!namePattern.IsMatch(names[0]) || !namePattern.IsMatch(names[1]) || names.Length != 2)
        {
            isValid = false;
        }

        return isValid;
    }
开发者ID:ROSSFilipov,项目名称:CSharp,代码行数:13,代码来源:PINValidation.cs

示例4: ShowLine

 static void ShowLine(string line)
 {
     string[] words = line.Split(',');
         Regex rgx = new Regex(@"\d+");
         int total = words.Length;
         string result = "";
         for(int i=0;i<total;i++){
             if(!rgx.IsMatch(words[i])) result += words[i] + ',';
         }
         if(result.Length>0)result = result.Substring(0,result.Length-1) + '|' ;
         for(int i=0;i<total;i++){
             if(rgx.IsMatch(words[i]))result += words[i] + ',';
         }
         Console.WriteLine(result.Substring(0,result.Length-1));
 }
开发者ID:ronmelcuba10,项目名称:CodeEval,代码行数:15,代码来源:Mixed+Content.cs

示例5: BitMaskUIScenesAttribute

	public BitMaskUIScenesAttribute()
	{
		Regex rootPath = new Regex(Regex.Escape("Assets/Scenes/")); /*+ Regex.Unescape(".+$")*/
		Regex ui = new Regex(".+(Panel)|(Popup)|(Screen)\\.unity");
		
		int size = 0;
		string[] allScenes = new string[UnityEditor.EditorBuildSettings.scenes.GetLength(0)];
		for(int i = 0 ; i < allScenes.Length ; i++)
		{
			allScenes[i] = UnityEditor.EditorBuildSettings.scenes[i].path;
			allScenes[i] = rootPath.Split(allScenes[i])[1];
			if(!ui.IsMatch(allScenes[i]) || !UnityEditor.EditorBuildSettings.scenes[i].enabled)
			{
				allScenes[i] = null;
			}
			else
				size++;
		}
		
		scenes = new string[size];
		int j = 0;
		for(int i = 0 ; i < allScenes.Length ; i++)
		{
			if(allScenes[i] != null)
			{
				scenes[j] = allScenes[i];
				j++;
			}
		}
	}
开发者ID:dannisliang,项目名称:FFEngine,代码行数:30,代码来源:BitMaskUIScenesAttribute.cs

示例6: Main

    public static void Main()
    {
        var triplet = new Regex(@"(.)\1\1");
        md5 = MD5.Create();

        salt = Console.ReadLine();
        int keysFound = 0;;
        int index = -1;

        while (keysFound < 64) {
          index++;
          string hash = GetHash(index);
          Match match = triplet.Match(hash);

          if (match.Success) {
        char letter = match.Groups[0].Value[0];
        var fiveOfThem = new Regex(new String(letter, 5));

        for (int j = index + 1; j <= index + 1000; j++) {
          if (fiveOfThem.IsMatch(GetHash(j))) {
            keysFound++;
            break;
          }
        }
          }

          hashCache.Remove(index);
        }

        Console.WriteLine(index);
    }
开发者ID:jayvan,项目名称:advent,代码行数:31,代码来源:14.cs

示例7: ProcessNativeResources

    void ProcessNativeResources(bool compress)
    {
        var unprocessedNameMatch = new Regex(@"^(.*\.)?costura(32|64)\.", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
        var processedNameMatch = new Regex(@"^costura(32|64)\.", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

        foreach (var resource in ModuleDefinition.Resources.OfType<EmbeddedResource>())
        {
            var match = unprocessedNameMatch.Match(resource.Name);
            if (match.Success)
            {
                resource.Name = resource.Name.Substring(match.Groups[1].Length).ToLowerInvariant();
                hasUnmanaged = true;
            }

            if (processedNameMatch.IsMatch(resource.Name))
            {
                using (var stream = resource.GetResourceStream())
                {
                    if (compress && resource.Name.EndsWith(".zip"))
                    {
                        using (var compressStream = new DeflateStream(stream, CompressionMode.Decompress))
                        {
                            checksums.Add(resource.Name, CalculateChecksum(compressStream));
                        }
                    }
                    else
                    {
                        checksums.Add(resource.Name, CalculateChecksum(stream));
                    }
                }
            }
        }
    }
开发者ID:rodrigoferrobrti,项目名称:Costura,代码行数:33,代码来源:NativeResources.cs

示例8: GetFirstString

 //public void LoadLeft(string name_en_s)
 //{
 //    data_conn cn = new data_conn();
 //    if (name_en_s != "")
 //    {
 //        DataSet ds = cn.mdb_ds("select top 5 * from TB_BBS where title like '%" + name_en_s + "%'", "bbs");
 //        Repeater1.DataSource = ds.Tables["bbs"].DefaultView;
 //        Repeater1.DataBind();
 //        string strYear = DateTime.Now.Year.ToString();
 //        string strMonth = DateTime.Now.Month.ToString();
 //        DataSet ds = cn.mdb_ds("select top 1 * from TB_BAF where months='" + strYear + "-" + strMonth + "' and Carriers like '%" + name_en_s + "%'", "baf");
 //        if (ds.Tables["baf"].Rows.Count > 0)
 //        {
 //            Literal8.Text = "<a href='../baf/#anchor" + ds.Tables["baf"].Rows[0]["id"].ToString() + "'>" + strMonth + "月" + name_en_s + "最新BAF/CAF</a><br />";
 //        }
 //        ds = cn.mdb_ds("select top 1 * from TB_THC where months='" + strYear + "-" + strMonth + "' and Carriers='" + name_en_s + "'", "thc");
 //        if (ds.Tables["thc"].Rows.Count > 0)
 //        {
 //            Literal9.Text = "<a href='../thc/#anchor" + ds.Tables["thc"].Rows[0]["id"].ToString() + "'>" + strMonth + "月" + name_en_s + "最新THC</a><br />";
 //        }
 //        ds = cn.mdb_ds("select top 5 * from TB_Search_Ship order by Num desc", "hot");
 //        Repeater2.DataSource = ds.Tables["hot"].DefaultView;
 //        Repeater2.DataBind();
 //    }
 //}
 public string GetFirstString(string stringToSub,int length)
 {
     Regex regex=new Regex("[\u4e00-\u9fa5\uff00-\uffef\u3000-\u303f\u2000-\u206f\u25a0-\u25ff]+", RegexOptions.Compiled);
     char[] stringChar = stringToSub.ToCharArray();
     StringBuilder sb = new StringBuilder();
     int nLength = 0;
     bool isCut = false;
     for (int i = 0; i < stringChar.Length; i++)
     {
         if (regex.IsMatch((stringChar[i]).ToString()))
         {
             sb.Append(stringChar[i]);
             nLength += 2;
         }
         else
         {
             sb.Append(stringChar[i]);
             nLength = nLength + 1;
         }
         if(nLength >length )
         {
             isCut = true;
             break;
         }
     }
     return sb.ToString();
 }
开发者ID:xiaomincui,项目名称:100allin,代码行数:52,代码来源:ports.aspx.cs

示例9: btnSearch_Click

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        messageContent.InnerHtml = "";

        if (String.IsNullOrEmpty(OrderFlUpload.FileName))
        {
            messageContent.InnerHtml = GetLocalResourceObject("Error1").ToString();
            arrData = "[[0.0]]";
            return;
        }

        string fileExt = System.IO.Path.GetExtension(OrderFlUpload.FileName);
        string allowexts = (ConfigurationManager.AppSettings["AllowUploadFileType"] != null) ? ConfigurationManager.AppSettings["AllowUploadFileType"].ToString() : "";    //定义允许上传文件类型
        if (allowexts == "") { allowexts =  ".*xls|.*xlsx";}

        Regex allowext = new Regex(allowexts);

        if (!allowext.IsMatch(fileExt)) //检查文件大小及扩展名
        {
            messageContent.InnerHtml = GetLocalResourceObject("Error2").ToString();
            arrData = "[[0.0]]";
            return;
        }

           arrData = getLatLngList();
           this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "key", "initialize();", true);
    }
开发者ID:WuziyiaoKingIris20140501,项目名称:KFC,代码行数:27,代码来源:UserOPInMap.aspx.cs

示例10: ValidateTextBoxes

    protected void ValidateTextBoxes(object sender, ServerValidateEventArgs args)
    {
        string strRegex = "^[a-zA-Z]+$";

        Regex regex = new Regex(strRegex);

        StringBuilder invalidTextBoxes = new StringBuilder();
        for (int i = 1; i <=6; i++)
        {
            string id = "PlayerName" + i;
            RadTextBox textbox = (RadTextBox)FindControl(id);
            if (textbox!=null)
            {
                if (!regex.IsMatch(textbox.Text) && textbox.Text != "")
                {
                    invalidTextBoxes.AppendLine(id);
                }
            }
        }
        if (invalidTextBoxes.Length != 0)
        {
            ValidationResult.Text = String.Format("INVALID: {0}", invalidTextBoxes.ToString());
            ValidationResult.Style["Color"] = "red";
        }
        else
        {
            ValidationResult.Text = "VALID";
            ValidationResult.Style["Color"] = "green";
        }
    }
开发者ID:TelerikAcademy,项目名称:QA-Academy,代码行数:30,代码来源:Default.aspx.cs

示例11: IsIPAddress

 public static bool IsIPAddress(string str1)
 {
     if (str1 == null || str1 == string.Empty || str1.Length < 7 || str1.Length > 15) return false;
         string regformat = @"^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$";
         Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);
         return regex.IsMatch(str1);
 }
开发者ID:ryutokeni,项目名称:glw,代码行数:7,代码来源:LoginPage.cs

示例12: LoadDialogueFromFile

    void LoadDialogueFromFile(string Filename)
    {
        string file = Application.dataPath +"/Dialogue_files/" + Filename +".txt";
        StreamReader sr;
        string line;
        int count = 0;
        Regex regx = new Regex ("//.*$");
        using (sr = new StreamReader (file)) {
            do{
                line = sr.ReadLine();
                count ++;
                if (line != null && !regx.IsMatch(line))
                {
                    if(line.Trim() != "")
                    {
                        string[] entries = line.Split('~');
                        if (entries.Length > 0)
                            LoadList(entries,count);
                    }
                }

            }
            while(line != null);
        }
    }
开发者ID:swapnilpatil427,项目名称:VIsualNovel,代码行数:25,代码来源:DialogueParser.cs

示例13: GetFirstString

    /// <summary>
    /// 截取字符串优化版
    /// </summary>
    /// <param name="stringToSub">所要截取的字符串</param>
    /// <param name="length">截取字符串的长度</param>
    /// <returns></returns>
    public static string GetFirstString(string stringToSub, int length)
    {
        #region
        Regex regex = new Regex("[\u4e00-\u9fa5]+", RegexOptions.Compiled);
        char[] stringChar = stringToSub.ToCharArray();
        StringBuilder sb = new StringBuilder();
        int nLength = 0;
        bool isCut = false;
        for (int i = 0; i < stringChar.Length; i++)
        {
            if (regex.IsMatch((stringChar[i]).ToString()))
            {
                sb.Append(stringChar[i]);
                nLength += 2;
            }
            else
            {
                sb.Append(stringChar[i]);
                nLength = nLength + 1;
            }

            if (nLength > length)
            {
                isCut = true;
                break;
            }
        }
        if (isCut)
            return sb.ToString() + "..";
        else
            return sb.ToString();
        #endregion
    }
开发者ID:kinggod,项目名称:21SourceCode,代码行数:39,代码来源:ArticleManage.aspx.cs

示例14: Include

    /// <summary>
    /// Test
    /// </summary>
    /// <param name="virtualPaths"></param>
    /// <returns></returns>
    public new Bundle Include( params string[] virtualPaths )
    {
        if ( HttpContext.Current.IsDebuggingEnabled )
        {
            // Debugging. Bundling will not occur so act normal and no one gets hurt.
            base.Include( virtualPaths.ToArray() );
            return this;
        }

        // In production mode so CSS will be bundled. Correct image paths.
        var bundlePaths = new List<string>();
        var svr = HttpContext.Current.Server;
        foreach ( var path in virtualPaths )
        {
            var pattern = new Regex( @"url\s*\(\s*([""']?)([^:)]+)\1\s*\)", RegexOptions.IgnoreCase );
            var contents = IO.File.ReadAllText( svr.MapPath( path ) );
            if ( !pattern.IsMatch( contents ) )
            {
                bundlePaths.Add( path );
                continue;
            }

            var bundlePath = ( IO.Path.GetDirectoryName( path ) ?? string.Empty ).Replace( @"\", "/" ) + "/";
            var bundleUrlPath = VirtualPathUtility.ToAbsolute( bundlePath );
            var bundleFilePath = String.Format( "{0}{1}.bundle{2}",
                                               bundlePath,
                                               IO.Path.GetFileNameWithoutExtension( path ),
                                               IO.Path.GetExtension( path ) );
            contents = pattern.Replace( contents, "url($1" + bundleUrlPath + "$2$1)" );
            IO.File.WriteAllText( svr.MapPath( bundleFilePath ), contents );
            bundlePaths.Add( bundleFilePath );
        }
        base.Include( bundlePaths.ToArray() );
        return this;
    }
开发者ID:fru,项目名称:System.Web.Optimization.Helper,代码行数:40,代码来源:CssBundle.cs

示例15: IsValidEmail

    public bool IsValidEmail(string email)
    {
        //regular expression pattern for valid email
        //addresses, allows for the following domains:
        //com,edu,info,gov,int,mil,net,org,biz,name,museum,coop,aero,pro,tv
        string pattern = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.
        (com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[a-zA-Z]{2})$";
        //Regular expression object
        Regex check = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);
        //boolean variable to return to calling method
        bool valid = false;

        //make sure an email address was provided
        if (string.IsNullOrEmpty(email))
        {
            valid = false;
        }
        else
        {
            //use IsMatch to validate the address
            valid = check.IsMatch(email);
        }
        //return the value to the calling method
        return valid;
    }
开发者ID:mominbd,项目名称:testing,代码行数:25,代码来源:Registration.aspx.cs


注:本文中的Regex.IsMatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。