使用javascript进行日期文本框验证 [英] date textbox validation using javascript
本文介绍了使用javascript进行日期文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hiii ,,,
我正在制作一个Web表单,其中当我从Ajax日历中选择to_date时,如果Todate是From_date,则是To_date和From_date.so的文本框.因此它会发出警报消息,否则将重点放在下一个日历上.
那么,我将如何实现呢?
请帮助我.......
谢谢和问候...
Mitesh
hiii,,,
i am making a web form in which there is textbox of To_date and From_date.so when i select to_date from the ajax calendar, if the selected date is Past date then now date. so it give alert message otherwise focus go onto next calendar.
so, how this will i achieve ?
Please Help Me.......
Thanks and Regards...
Mitesh
推荐答案
尝试一下:
Try this:
protected string CheckDateErrors(string dateGiven)
{
// let's make sure that the date entered by user
// does not exceed the present date or goes back
// over a year.
// we need to try parse!
DateTime userDate = DateTime.Parse(dateGiven);
//DateTime userDate;
int userYear = userDate.Year;
int userMonth = userDate.Month;
int userDay = userDate.Day;
// not valid! user entered future date, can't allow this to happen
if (userDate.CompareTo(DateTime.Now) > 0)
{
//this.tbBeginDate.ForeColor = Color.Red;
//this.tbBeginDate.BorderColor = Color.Red;
return "* Cannot Enter Future Dates;";
}
// date cannot be more than one year old.
else if (userDate.CompareTo(DateTime.Now) <= 0)
{
int difference = DateTime.Today.Year - userYear;
// going too far back; now allowed.
if (userYear < (DateTime.Today.Year - 1))
{
return "* Cannot Enter Past One Year: Compared Years;";
}
else if ((difference == 1) &&
(userMonth < DateTime.Today.Month))
{
return "* Cannot Enter Past One Year: Compared Months;";
}
else if ((difference == 1) &&
(userMonth >= DateTime.Today.Month) &&
(userDay < DateTime.Today.Day))
{
return "* Cannot Enter Past One Year: Compared Days";
}
return "none";
}
return "none";
}
在此处找到它 [
Found it here[^]
Hello Mitesh,
请在下面找到可能对您有帮助的链接:
http://pankajlalwani.wordpress .com/2009/12/23/asp-net-ajax-calendar-extender-and-past-date-validation-javascript/ [ http://chakkaradeep.wordpress.com/2008/08/01/aspnet -ajax-calendarextender-and-validation/ [ http://codingform.blogspot.in/2009/07/ajax-calendarextender-date- validation.html [ ^ ]
Hello Mitesh,
Please find below links which might help you:
http://pankajlalwani.wordpress.com/2009/12/23/asp-net-ajax-calendar-extender-and-past-date-validation-javascript/[^]
http://chakkaradeep.wordpress.com/2008/08/01/aspnet-ajax-calendarextender-and-validation/[^]
http://codingform.blogspot.in/2009/07/ajax-calendarextender-date-validation.html[^]
可能会帮助您.
http://www.dreamincode.net/forums/topic/99238-date-validation/ [ ^ ]
May be this will help you.
http://www.dreamincode.net/forums/topic/99238-date-validation/[^]
这篇关于使用javascript进行日期文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文