【发布时间】:2015-07-18 15:13:12
【问题描述】:
我想使用正则表达式来验证在我的文本框 txtWeb 中输入的 URL,但是我发现的所有正则表达式在 Visual Studio 2013 中都不起作用。错误是由所有反斜杠和点引起的。不知道有没有办法让它工作?这是我要使用的正则表达式:
/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
这就是我尝试使用它的方式:
if (txtWeb.Text != "")
{
Regex regex = new Regex("/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/");
Match match = regex.Match(txtWeb.Text);
if (!match.Success)
{
MetroMessageBox.Show(this, "Ce site web est invalide", "Message d'erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
erreur = false;
}
}
【问题讨论】:
标签: c# regex winforms visual-studio-2013