帮助进行日期验证 [英] Help with date validation

查看:35
本文介绍了帮助进行日期验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!我有一个包含开始日期和结束日期的共享点列表。我希望有一个日期验证,其中结束日期是在开始日期后7天或更长时间之后,同时用户不应该选择星期日或星期六。任何想法如
我如何做到这一点。 

Hello! All i have a sharepoint list with start date and end date. I want to have a date validation where the end date has be after 7 days or more after the start days and user at the same time should not be able to select sunday or saturday. Any ideas as to how i can do this. 

谢谢 

推荐答案

您好,

您可以使用PreSaveAction验证结束日期必须大于7天的开始日期,如下所示:

You could use PreSaveAction to validate the end date must greater than start date with 7 days like this:

<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript">

function PreSaveAction()
{
  var start=new Date(


(" input [title ='start date'] ")VAL())。

var end = new Date(
("input[title='start date']").val()); var end=new Date(


(" input [title ='end date']")。val());
var diff = end-start;
var diffdays = parseInt(diff / 1000/60/60/24);
if(diffdays> 7)
{
return true;
}
其他
{
提醒("请确保结束日期比开始日期至少大7天");
返回false;
}
}

< / script>
("input[title='end date']").val()); var diff=end-start; var diffdays=parseInt(diff / 1000 / 60 / 60 / 24); if(diffdays > 7) { return true; } else { alert("please make sure the end date is at least 7 days greater than start date"); return false; } } </script>

将代码添加到内容编辑器Web部件中以使列表新表单生效,单击保存按钮时会弹出警告消息并阻止保存数据:

Add the code into the Content Editor Web Part for the list new form to make it work, when clicking saving button it will pop up the warning message and prevent saving data:

谢谢

最好的问候


这篇关于帮助进行日期验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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