本文整理汇总了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; //定义输入焦点在最后一个字符
}
}
示例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 = "";
}
示例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 = "";
}
}
示例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(); ;
}
示例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));
}
}
示例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;
}
示例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));
}
}
}
示例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;
}
示例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.");
}
示例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);
}
示例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;
}
示例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;
}
示例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 + " 个";
}
示例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();
}
示例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;
}