简体   繁体   English

验证日期-用户只能选择下个月的日期

[英]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.

相关问题 验证日期应为JavaScript中月份的最后日期 - validate date should be last date of month in javascript 使用javascript验证表单,我在其中有从和到日期选择器,并且它应仅允许当前日期和有效时间,而不允许第二天 - validate the form using javascript where i have from and to date picker and it should allow only current date and valid time not the next day pickaday.js用户只能选择未来15天中的任何日期 - pickaday.js user can select any date from next 15 days only 仅按年,月和日期比较日期? - Comparing dates only by year, month and date? 日历禁用下个月的日期 - Calendar disable dates from next month 需要一个Javascript日历,该日历只应显示与文本框中日期对应的下一个日期 - Need a Javascript calendar that should only show next dates corresponding to the date in textbox 我只需要在开始日期选择的日期选择器中显示未来一个月的日期 - I need to show only future one month dates in the date picker from the start date selection 使用Eonasdan Link DateTime Picker限制用户仅在一个月之间选择日期 - Using Eonasdan Link DateTime Picker Restrict User to select date between a Month only jQuery UI多日期选择器| 选择月份的所有日期 - jquery ui multi date picker | select all the dates of month 我应该如何按照下面的代码从单个日期选择器中获取日期和月份 select? - How should I follow the code below to select the date and month from a single datepicker?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM