Date validation using JavaScript

InfoPath alternatives for form designing SharePoint
In this post we will discuss about date validation using JavaScript.
Here is a date validation through JavaScript that will give an alert message if you try to give a date less than today. It will always take the future date.
Below is the full HTML code:
 <head runat=”server”>
 <script language=”javascript” type=”text/javascript”>
     function validateDate() {
         var expDate = document.getElementById(‘txtDate’).value;
         var date = expDate.substring(0, 2);
         var month = expDate.substring(3, 5);
         var year = expDate.substring(6, 10);
         var myDate = new Date(year, month – 1, date);
         var today = new Date();
         if (myDate > today) {
         }
         else {
             alert(‘Please enter a date greater than today !’);
             return false;
         }
     }
    </script>
    <title>JavaScript date validation</title>
</head>
<body>
    <form id=”form1″ runat=”server”>
    <div>
        <asp:TextBox ID=”txtDate” runat=”server”></asp:TextBox><br />
        <asp:Button ID=”btnValidate” runat=”server” Text=”Click to Validate” OnClientClick=”return validateDate();” />
    </div>
    </form>
</body>
Check the figure below for more information:

Similar SharePoint 2013 Tutorials


About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply