简体   繁体   English

使用JavaScript进行客户端日期验证

[英]Client side date validation using JavaScript

I have a form in which there are 2 jQuery datepickers, one for start date and a second one for end date. 我有一种形式,其中有2个jQuery datepicker,一个用于开始日期,第二个用于结束日期。 I want to add date range validation on them so client cannot select today's date and also future dates. 我想在其上添加日期范围验证,以便客户无法选择今天的日期以及将来的日期。

@{Html.BeginForm("ExportToExcel", "marketing", FormMethod.Get);}
<input type="hidden" value="@ViewBag.StartDate" name ="EXsd" />
<input type="hidden" value="@ViewBag.EndDate" name = "EXst" />
@{Html.EndForm();}

Can anyone please tell me how to write the JavaScript function to add date validation? 谁能告诉我如何编写JavaScript函数来添加日期验证?

http://jqueryui.com/datepicker/#min-max http://jqueryui.com/datepicker/#min-max

Restrict the range of selectable dates with the minDate and maxDate options. 使用minDate和maxDate选项限制可选日期的范围。 Set the beginning and end dates as actual dates (new Date(2009, 1 - 1, 26)), as a numeric offset from today (-20), or as a string of periods and units ('+1M +10D'). 将开始日期和结束日期设置为实际日期(新的Date(2009,1-1,26)),设置为今天(-20)的数字偏移量,或设置为一串周期和单位('+ 1M + 10D') 。 For the last, use 'D' for days, 'W' for weeks, 'M' for months, or 'Y' for years. 最后,使用“ D”代表几天,使用“ W”代表星期,使用“ M”代表几个月,或使用“ Y”代表几年。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM