我如何根据以下要求验证日期 [英] how do i validate date as required below

查看:73
本文介绍了我如何根据以下要求验证日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javascript验证:



验证日期格式为MM / DD / YYYY,

必须是真实日期和它等于或早于当前日期。

如果验证失败,将显示以下错误消息

无效日期。只允许使用数字和正斜杠(/)字符。有效格式为MM / DD / YYYY。





请帮我解释一下代码。

javascript validation:

validate the format of the Date as MM/DD/YYYY,
Has to be a real date and that it is equal to or earlier than the current date.
If the validation fails the following error message will be shown
Invalid Date. Only number and forward slash (/) characters are allowed. The valid format is MM/DD/YYYY.


Please help me with the code.

推荐答案

查看此链接,它将帮助您获得许多想法:

system.datetime.date

你也可以在c#中使用这些代码。:

check this link , it will help you to get many ideas :
system.datetime.date
and you can use this codes in c# too .:
DateTime dt = DateTime.Parse("02/22/2012");//you can put a textbox.text instead this date
if (dt.ToString("mm/dd/yyyy") == dt.GetDateTimeFormats()[3])// an if statement check if format is mm/dd/yyyy
    MessageBox.Show(dt.ToString());
else
    MessageBox.Show(dt.ToString("Invalid Date. Only number and forward slash (/) characters are allowed. The valid format is MM/DD/YYYY."));


这篇关于我如何根据以下要求验证日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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