ASP.NET C#中的日期验证 [英] Date Validation in ASP.NET C#

查看:89
本文介绍了ASP.NET C#中的日期验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我正在做一个电子商务项目。因为我在其中一个页面中遇到问题,客户在其中注册了他的个人信息。在出生日期列中,它正在考虑今天和未来的价值也是日期。如果它早到达日,我想要取值。否则应该显示错误。怎么做?请帮我验证出生日期。

谢谢。

解决方案

 DateTime dOB = ... 
DateTime now = DateTime.Now;
if (dOB < now)
{
.. 。
}

您可能也希望看一下这一点,特别是如果您有最低年龄,您可以接受以下订单:与年龄一起工作:它与TimeSpan不同! [ ^ ]


你好



这就是我的做法。



 DateTime selectedDOB = Convert.ToDateTime(DatePicker.Text); 
string cDate = DateTime.Now.ToShortDateString();

DateTime currentDate = Convert.ToDateTime(cDate);
if (selectedDOB < currentDate)
{
// 此处出现错误消息


}


两个日期的比较将帮助您解决问题。 .Net允许您轻松地进行比较而无需任何转换。查看此链接 [ ^ ]以获取有关日期比较返回的结果的详细信息。

hello everyone..i am doing one e-commerce project.In that i am having problem in one of the page where customer sign up with his personal details.In date of birth column it is taking the values for today and future date also.I want values to be taken if it is earlier to tat day otherwise error should be displayed.How to do this?Please help me in validating date of birth.
Thank You.

解决方案

DateTime dOB = ...
DateTime now = DateTime.Now;
if (dOB < now)
    {
    ...
    }

You might want to look at this as well, perticularly if you have a minimum age you can accept orders from: Working with Age: it's not the same as a TimeSpan![^]


Hello

this is how I did mine.

DateTime selectedDOB = Convert.ToDateTime(DatePicker.Text);
        string cDate = DateTime.Now.ToShortDateString();

        DateTime currentDate = Convert.ToDateTime(cDate);
        if (selectedDOB < currentDate)
        {
           //Error message here
           
            
        }


Comparison of both dates will help you solve your issue. .Net allows you to do that comparison easily without any kind of conversions. Look into the this link[^] to get details about the results returned by the comparison of dates.


这篇关于ASP.NET C#中的日期验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆