[英]Validate date - User should only select dates from next month
I have a datepicker field (SharePoint 2013) in custom list. 我在自定义列表中有一个日期选择器字段(SharePoint 2013)。 I am trying to do a validation for the particular date field (DtStartDate).
我正在尝试对特定日期字段(DtStartDate)进行验证。 Conditions are: 1) User should not select past dates from current date 2) User should be selecting dates from next month from current date.
条件是:1)用户不应从当前日期选择过去的日期2)用户应从当前日期选择下个月的日期。 Example: if date is 4/26/2017, then user should not select any date till 5/26/2017.
例如:如果日期为4/26/2017,则用户不应选择任何日期,直到5/26/2017。 If they select, I want to show an error message.
如果他们选择,我想显示一条错误消息。
I have tried the below code: 我尝试了以下代码:
var dtStartDate = $("input[title='Start Date Required Field']").val();
// Get today's date
var todaysDate = new Date();
// Create date from input value
if(dtStartDate.length > 0)
{
inputStartDate = new Date(dtStartDate);
// call setHours to take the time out of the comparison
if( (inputStartDate.setHours(0,0,0,0) == todaysDate.setHours(0,0,0,0)) || (inputStartDate < todaysDate ) ) {
// StartDate equals today's date or Date is in the Past
msg = msg + "<br/> Demand Start Date should be greater than Today's Date";
}
}
How to check the validation for the 2nd case? 如何检查第二种情况的有效性? Thanks
谢谢
Tru将日期添加到日期选择器
Datefrom.MinDate = DateTime.Now.AddDays(60);
hope this will help 希望这会有所帮助
var d = new Date(); // current date var date = d.setMonth(d.getMonth() + 1); // add month to the current date var inputDate = new Date(d.setMonth(d.getMonth() + 2)); // add two months to the current date console.log('comparison date - ' + new Date(date)); console.log('input date - ' + inputDate); if(date < inputDate.getTime()) console.log('valid date'); else console.log('invalid date');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.