我有一些代码可以根据正则表达式检查输入的字段,尽管出于某种原因(无论我在字段中输入什么,它都会返回 flase。我错过了什么吗?
private void textBox5_Validating(object sender, CancelEventArgs e)
{
String AllowedChars = @"^a-zA-Z0-9.$";
if (Regex.IsMatch(textBox5.Text, AllowedChars))
{
MessageBox.Show("Valid");
}
else
{
MessageBox.Show("Invalid");
}
}
最佳答案
正则表达式对我来说毫无意义。这个会(注意用于定义字母表的方括号):
String AllowedChars = @"^[a-zA-Z0-9]*$";
关于C# - 在 if 语句中使用正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6415620/