无效的出生日期 [英] invalid date of birth

查看:127
本文介绍了无效的出生日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个特殊的简历程序,但遇到了问题
在我的程序中.我使用了一个显示生日的masktaskbok,但是用户插入了程序中接受的无效生日.但我希望出生日期有效,因此请提供此问题的代码.
谢谢........

I made a particular program of resume, but I have a problem
in my program. I take a masktaskbok of showing date of birth but user inserts date of birth that is invalid that is accepted in the program. But I want date of birth to be valid, so please give code of this problem.
Thank you........

推荐答案

您可以使用
测试输入的值以查看其是否为有效日期. DateTime.Parse()并捕获所有引发的异常.该函数将尝试将用户日期字符串解析为DateTime 对象.
You can test the value entered to see if it is a valid date using
DateTime.Parse() and catch any exception thrown. The function will try to parse the users date string into a DateTime object.


使用CompareValidator并将Type设置为Date.
Use CompareValidator and set Type to Date.


此处"一个主意.如果它是GUI应用程序,则可以使用3个组合框,然后在表单加载说明日期时为它们提供值,您可以在表单加载中使用代码:

Here''s an idea. If it''s a GUI application, then you may use 3 comboboxes and then give them values when the form load say for dates you can use the code in form load:

for(int i =1;i<=31;i++)
{
cbodate.Items.Add(i);
}



然后,您可以使用if else if condition语句来检查生日日期值,例如,如果用户使用此条件语句输入2月31日,则可以施加限制,如果用户输入了错误的日期,则可能会显示一个消息框,或者错误的月份,其中包含错误的日期,例如4月31日.

现在,如果它是一个ASP.NET应用程序,那么我的朋友我建议您使用相同的技巧或使用框架中可用的任何验证ctrl.

这只是做您想做的另一种方法,但是如果您坚持使用maskedtxtbx,那么我对此没有任何建议.....或者您也可以使用DATETIMEPICKER并相应地设置验证...

谢谢&问候,
基数:-\​​

如果对我的回答有所帮助,请对我的回答进行评分.谢谢.



And then you may use if else if condition statement to check in the date of birth value, say you can impose a restriction if the user enters 31st of Feb using this conditional statement you may show a messagebox if the user enters a wrong date, or wrong month containing a wrong date say 31st april.

Now if it''s an ASP.NET application, then my friend I may suggest you to use the same trick or use any validating ctrls available in the framework.

This is just another method of doing what you want to do but if you insist on using maskedtxtbx, then I have no suggestions on that..... or you can also use DATETIMEPICKER and set validations accordingly...

Thanks & regards,
Radix :-\

Do rate my answer if you find it helpful to some extent. Thank you.


这篇关于无效的出生日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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