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


C# System.Text.RegularExpressions.Regex.IsMatch方法代码示例

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


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

示例1: OnTextChanged

        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            // 只读, 不处理
            if (this.ReadOnly) return;

            string regex = @"^[\w ]+$"; //匹配数字、字母、汉字
            if (isNumber) regex = "^[0-9]*$";  //匹配数字 
            var reg = new System.Text.RegularExpressions.Regex(regex);// 
            var str = this.Text.Replace(" ", "");
            var sb = new StringBuilder();
            if (!reg.IsMatch(str))
            {
                for (int i = 0; i < str.Length; i++)
                {
                    if (reg.IsMatch(str[i].ToString()))
                    {
                        sb.Append(str[i].ToString());
                    }
                }
                this.Text = sb.ToString();
                this.SelectionStart = this.Text.Length;    //定义输入焦点在最后一个字符          
            }
        }
开发者ID:FeelingMars,项目名称:DispatchPlatform,代码行数:25,代码来源:TextBoxEx.cs

示例2: button2_Click

 private void button2_Click(object sender, EventArgs e)
 {
     System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"\d+");
     if (listBox1.SelectedIndex > -1 && reg.IsMatch(textBox1.Text) && reg.IsMatch(textBox2.Text))
     {
         res = string.Format("{0}({1},{2})",listBox1.Items[listBox1.SelectedIndex].ToString(),textBox1.Text,textBox2.Text);
     }
     else
         res = "";
 }
开发者ID:eddylin2015,项目名称:school_timetable,代码行数:10,代码来源:FormSubjectTeacherInput.cs

示例3: button1_Click

 private void button1_Click(object sender, EventArgs e)
 {
     System.Text.RegularExpressions.Regex reg=new System.Text.RegularExpressions.Regex(@"\d+");
     if (comboBox1.Text != "" && reg.IsMatch(textBox1.Text)&& reg.IsMatch(textBox2.Text))
     {
         res = string.Format("{0}({1},{2})", comboBox1.Text, textBox1.Text, textBox2.Text);
     }
     else
     {
         res = "";
     }
 }
开发者ID:eddylin2015,项目名称:school_timetable,代码行数:12,代码来源:FormSubjectTeacherInput.cs

示例4: FunctionCall

        public FunctionCall(ISyntaxNode parent, ref string Input)
            : base(parent)
        {
            Pattern regExPattern =
                "^\\s*" +
                new Group("def",
                    new Group("identifier", Provider.identifier) +
                    "\\s*\\(" +
                    new Group("params", "[a-zA-Z_0-9*\\+/!&|%()=,\\s]*") +
                    "\\)");

            System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(regExPattern);
            System.Text.RegularExpressions.Match match = regEx.Match(Input);

            if (!match.Success)
                throw new ParseException();
            //if (match.Index != 0)
            //	throw new ParseException();
            Input = Input.Remove(0, match.Index+match.Length); // Also removes all starting spaces etc...

            Identifier = match.Groups["identifier"].Value;

            //System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("\\s*,\\s*" + new Group("", ""));
            if (!parent.IsFunctionDeclared(Identifier))
                throw new SyntaxException("Syntax error: Call of undeclared function \"" + Identifier + "\".");

            String param = match.Groups["params"].Value;
            List<IRightValue> parameters = new List<IRightValue>();

            System.Text.RegularExpressions.Regex endRegEx = new System.Text.RegularExpressions.Regex("^\\s*$");
            System.Text.RegularExpressions.Regex commaRegEx = new System.Text.RegularExpressions.Regex("^\\s*,\\s*");

            while (!endRegEx.IsMatch(param))
            {
                IRightValue val = IRightValue.Parse(this, ref param);
                if (val == null)
                    throw new SyntaxException ("syntax error: Can't parse rvalue at function call.");

                parameters.Add(val);

                if (endRegEx.IsMatch(param))
                    break;

                System.Text.RegularExpressions.Match comma = commaRegEx.Match(param);
                if (!comma.Success)
                    throw new SyntaxException("syntax error: Function arguments must be separated by a comma.");

                param = param.Remove(0, comma.Index + comma.Length); // Also removes all starting spaces etc...
            }

            this.Parameters = parameters.ToArray(); ;
        }
开发者ID:Thenarden,项目名称:RPCC,代码行数:52,代码来源:FunctionCall.cs

示例5: Check

 public void Check(Image img)
 {
     if (text.Length > 0)
     {
         System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(pattern);
         if (!r.IsMatch(text))
         {
             MessageBox.Show(errorMessageLocal);
             resultLocal = false;
             img.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/img/registration/" + resultServer.ToString() + ".png", UriKind.Relative));
         }
         else
         {
             resultLocal = true;
             if (type != "password")
             {
                 ServerCheck(img);
             }
             else
             {
                 resultServer = true;
                 img.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/img/registration/" + resultServer.ToString() + ".png", UriKind.Relative));
             }
         }
     }
     else
     {
         resultLocal = false;
         resultServer = false;
         img.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/img/registration/" + resultServer.ToString() + ".png", UriKind.Relative));
     }
 }
开发者ID:asdForever,项目名称:GeneralThings,代码行数:32,代码来源:CorrectionCheck.cs

示例6: GenerateCode

        /// <summary>
        /// Function that builds the contents of the generated file based on the contents of the input file
        /// </summary>
        /// <param name="inputFileContent">Content of the input file</param>
        /// <returns>Generated file as a byte array</returns>
        protected override byte[] GenerateCode(string inputFileContent)
        {

            //if (InputFilePath.EndsWith("_md"))
            var mdRegex = new System.Text.RegularExpressions.Regex(@"\w+\.\w+_md");
            if (mdRegex.IsMatch(Path.GetFileName(InputFilePath)))
            {
                try
                {
                    var input = File.ReadAllText(InputFilePath);
                    var md = new MarkdownSharp.Markdown();
                    var output = md.Transform(input);
                    return ConvertToBytes(output);
                }
                catch (Exception exception)
                {
                    GeneratorError(0, exception.Message, 0, 0);
                }
            }
            else
            {
                GeneratorError(0, "The Markdown tool is only for Markdown files with the following filename format: filename.[required_extension]_md", 0, 0);
            }

            return null;
        }
开发者ID:stachow,项目名称:Markdown-For-Visual-Studio,代码行数:31,代码来源:Markdown.cs

示例7: CheckString

        public static void CheckString(FieldInfo fieldInfo, string val)
        {
            if (val == null)
                return;

            if (fieldInfo.maxLength > 0)
            {
                if (!string.IsNullOrEmpty(val))
                {
                    if (val.Length > fieldInfo.maxLength)
                    {
                        throw new ValidationException(string.Format(ErrorStrings.ERR_VAL_EXCEEDS_MAXLENGTH, fieldInfo.fieldName, fieldInfo.maxLength));
                    }
                }
            }

            if (!string.IsNullOrEmpty(val) && !string.IsNullOrEmpty(fieldInfo.regex))
            {
                var rx = new System.Text.RegularExpressions.Regex(fieldInfo.regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                if (!rx.IsMatch(val))
                {
                    throw new ValidationException(string.Format(ErrorStrings.ERR_VAL_IS_NOT_VALID, fieldInfo.fieldName));
                }
            }
        }
开发者ID:NishantTeria,项目名称:jRIApp,代码行数:25,代码来源:ValidationHelper.cs

示例8: validarCorreo

        public static bool validarCorreo(string cadenaUsuario)
        {
            bool val = true;
            bool result = false;
            foreach (char c in cadenaUsuario)
            {
                if (c == '"')
                {
                    val = false;
                    break;
                }
            }

            if (val == true)
            {
                patron = @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
                auto = new System.Text.RegularExpressions.Regex(patron);
                result = auto.IsMatch(cadenaUsuario);
            }
            else
            {
                result = false;
            }

            return result;
        }
开发者ID:Alejandro13,项目名称:hub,代码行数:26,代码来源:validacion.cs

示例9: HandleCreateAccount

        private static string HandleCreateAccount(HttpServer server, HttpListenerRequest request, Dictionary<string, string> parameters)
        {
            if (!parameters.ContainsKey("username")) throw new Exception("Missing username.");
            if (!parameters.ContainsKey("password")) throw new Exception("Missing password.");

            string username = parameters["username"];
            string password = parameters["password"];

            if (Databases.AccountTable.Count(a => a.Username.ToLower() == username.ToLower()) > 0) return JsonEncode("Username already in use!");

            System.Text.RegularExpressions.Regex invalidCharacterRegex = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]");
            if (invalidCharacterRegex.IsMatch(username)) return JsonEncode("Invalid characters detected in username!");

            Random getrandom = new Random();
            String token = getrandom.Next(10000000, 99999999).ToString();
            AccountEntry entry = new AccountEntry();
            entry.Index = Databases.AccountTable.GenerateIndex();
            entry.Username = username;
            entry.Password = password;
            entry.Verifier = "";
            entry.Salt = "";
            entry.RTW_Points = 0;
            entry.IsAdmin = 0;
            entry.IsBanned = 0;
            entry.InUse = 0;
            entry.extrn_login = 0;
            entry.CanHostDistrict = 1;
            entry.Token = token;
            Databases.AccountTable.Add(entry);

            Log.Succes("HTTP", "Successfully created account '" + username + "'");
            return JsonEncode("Account created!\n\nYour token is: " + token + ".\nCopy and paste given token in \"_rtoken.id\" file and put it in the same folder where your \"APB.exe\" is located.");
        }
开发者ID:fiki574,项目名称:rAPB,代码行数:33,代码来源:HttpServer.Handlers.cs

示例10: IsDateTimeTest

 public void IsDateTimeTest()
 {
     System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$");
     var d = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
     var res= reg.IsMatch(d);
     Assert.IsTrue(res);
 }
开发者ID:zidanfei,项目名称:Dot.Utility,代码行数:7,代码来源:DataConvertTests.cs

示例11: CreateBounds

        static FunctionBounds CreateBounds(string[] parts)
        {
            System.Text.RegularExpressions.Regex rg_bound = new System.Text.RegularExpressions.Regex("{.*}");
            FunctionBounds Bounds = new FunctionBounds();

            foreach (string part in parts.Skip(1))
            {
                if (rg_bound.IsMatch(part))
                {
                    string[] bound = part.Remove(part.Length - 1, 1).Remove(0, 1).Split(',');

                    Bounds.AddBound((float)Convert.ToDouble(bound[0]), (float)Convert.ToDouble(bound[bound.Length - 1]));

                    if (bound.Length == 3)
                    {
                        Bounds.AddStep((float)Convert.ToDouble(bound[1]));
                    }
                    else
                    {
                        Bounds.AddDefaultStep((float)Convert.ToDouble(bound[0]), (float)Convert.ToDouble(bound[bound.Length - 1]));
                    }

                }
                else
                {
                }
            }
            return Bounds;
        }
开发者ID:SawyerHopkins,项目名称:SciLib,代码行数:29,代码来源:Utility.cs

示例12: getByteFromGMKBString

 public static long getByteFromGMKBString(String text)
 {
     long result = 0;
     System.Text.RegularExpressions.Regex gbReg = new System.Text.RegularExpressions.Regex(@"(\d+)GB", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex kbReg = new System.Text.RegularExpressions.Regex(@"(\d+)KB", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex mbReg = new System.Text.RegularExpressions.Regex(@"(\d+)MB", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex bReg = new System.Text.RegularExpressions.Regex(@"(\d+)B", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     if (bReg.IsMatch(text)) {
         var m = bReg.Match(text);
         result += long.Parse(m.Groups[1].Value);
     }
     if (kbReg.IsMatch(text)) {
         var m = kbReg.Match(text);
         result += long.Parse(m.Groups[1].Value) * BaseByte;
     }
     if (mbReg.IsMatch(text)) {
         var m = mbReg.Match(text);
         result += long.Parse(m.Groups[1].Value) * BaseByte * BaseByte;
     }
     if (gbReg.IsMatch(text)) {
         var m = gbReg.Match(text);
         result += long.Parse(m.Groups[1].Value) * BaseByte * BaseByte * BaseByte;
     }
     return result;
 }
开发者ID:fushihara,项目名称:DD-windows,代码行数:25,代码来源:ByteFormatter.cs

示例13: openFileDialog1_FileOk

 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
 {
     String filePath = openFileDialog1.FileName;
     openFileDialog1.InitialDirectory = filePath;
     mobiles.Clear();
     listBox1.Items.Clear();
     if (File.Exists(filePath)){              
         using (StreamReader sr = File.OpenText(filePath))
         {
             string s = "";
             while ((s = sr.ReadLine()) != null)
             {
                 System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^\d+$");
                 if (s.Length == 11&& rex.IsMatch(s))
                 {
                     if (!mobiles.Contains(s))
                     {
                         mobiles.Add(s);
                         listBox1.Items.Add(s);
                     }
                 }
             }
         }
     }
     msgLab.Text = "你将给 " + mobiles.Count + " 个人群发信息,短信字数共计为 " + contentTxt.Text.Length + " 个";
 }
开发者ID:wx9106,项目名称:sms_chuanglan_csharp,代码行数:26,代码来源:Send.cs

示例14: CheckRouting

 /// <summary>
 /// ajax method for chek routing
 /// </summary>
 /// <param name="pattern"></param>
 /// <param name="replaceStr"></param>
 public void CheckRouting(string pattern, string replaceStr)
 {
     System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(pattern);
     string flag = reg.IsMatch(replaceStr) ? "匹配" : "不匹配";
     RenderText(flag);
     CancelView();
 }
开发者ID:biguoting,项目名称:MVCWebApplication,代码行数:12,代码来源:HomeController.cs

示例15: ValidateEmail

 public bool ValidateEmail()
 {
     bool result = true;
     try
     {
         if (txtMailId.Text.Trim() != string.Empty)
         {
             System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");//^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$
             if (txtMailId.Text.Length > 0)
             {
                 if (!rEMail.IsMatch(txtMailId.Text))
                 {
                     MessageBox.Show("Invalid Email", "Pharmasoft", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     result = false;
                     txtMailId.Focus();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SM" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     return result;
 }
开发者ID:jsoques,项目名称:openmiracle,代码行数:25,代码来源:frmSendMail.cs


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