【问题标题】:why is my date validator not working?为什么我的日期验证器不起作用?
【发布时间】:2009-08-06 10:40:43
【问题描述】:

我正在尝试使用自定义验证器验证输入到文本框中的日期:

string CombinedDate = String.Format("{0}-{1}-{2}", txtDay.Text, txtMonth.Text, txtYear.Text);

if (DateTime.TryParseExact(CombinedDate, "dd-MM-YYYY", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out date))
{
    args.IsValid = true;
}
else
{
    args.IsValid = false;
}

但它在 21-02-2005 失败了,这是为什么呢? 以及我该如何解决它

【问题讨论】:

  • 还有哪些其他日期失败?

标签: c# .net datetime


【解决方案1】:

YYYY 必须是 yyyy

有关 MSDN 中的其他格式,请参阅 here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 2017-07-03
    相关资源
    最近更新 更多