100分 高手来啊、

来源:百度知道 编辑:UC知道 时间:2024/05/28 10:31:12
protected void Button1_Click(object sender, EventArgs e)
{

Regex a = new Regex(@"^((((31\/(0?[13578]|1[02]))|((29|30)\/(0?[1,3-9]|1[0-2])))\/
(1[6-9]|[2-9]\d)?\d{2})|(29\/0?2\/(((1[6-9]|[2-9]\d)?(0[48]|
[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))|
(0?[1-9]|1\d|2[0-8])\/((0?[1-9])|(1[0-2]))\/((1[6-9]|[2-9]\d
)?\d{2})) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$");

if (a.IsMatch(TextBox1.Text.ToString()))
Label1.Text = "成功";
else
Label1.Text = "失败";
}
} 这样不对 为什么 快 很急
我自己弄个好了 谢谢大家了 哈哈 所以把分数给最多的那个 呵呵

protected void Button1_Click(object sender, EventArgs e)
{

String a = @"^((((31\/(0?[13578]|1[02]))|((29|30)\/(0?[1,3-9]|1[0-2])))\/
(1[6-9]|[2-9]\d)?\d{2})|(29\/0?2\/(((1[6-9]|[2-9]\d)?(0[48]|
[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))|
(0?[1-9]|1\d|2[0-8])\/((0?[1-9])|(1[0-2]))\/((1[6-9]|[2-9]\d
)?\d{2})) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$";

RegexOptions options = ((RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline) | RegexOptions.IgnoreCase);
Regex reg = new Regex(a, options);
if (reg.IsMatch(TextBox1.Text))
Label1.Text = "成功";
else
Label1.Text = "失败";
}
}
注意引用命名空间
using System.Text.RegularExpressions;
如果你的正则表达式没问题的话,这样写就可以了,试一下,希望能帮到你。

因为你没有告诉我提示什么错误,所以我不知道回答

错误提示?
要不怎么调试

匹配来说没有什么问题
如果编译出错应该没有引用命名空间using System.Text.