问个正则问题``
可以输入合法的年月日,只需精确到日
4位年,1-12的月,1-31的日
2012-04-23 可以
2012-4-3 可以
2012-14-3 错误
2012-4-33 错误Regex regex = new Regex(@"");
Match match = regex.Match(mydate);
if (match.Success)
{
success = true;
} 可以直接在这个代码上改```
可以输入合法的年月日,只需精确到日
4位年,1-12的月,1-31的日
2012-04-23 可以
2012-4-3 可以
2012-14-3 错误
2012-4-33 错误Regex regex = new Regex(@"");
Match match = regex.Match(mydate);
if (match.Success)
{
success = true;
} 可以直接在这个代码上改```
string s = "2012-04-23";
DateTime dt;
if (DateTime.TryParseExact(s, "yyyy-MM-dd", null, DateTimeStyles.None, out dt))
//验证通过
日期用正则反而不好
DateTime dt;
bool flag = DateTime.TryParse("时间字符串", out dt);
if(flag)
{
//符合
}
else
{
//不符合
}