EnjoySharePoint YouTube Channel

Date validation using JavaScript

In this post, we will discuss date validation using JavaScript.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

You can also check out my previous posts on:
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;
    <title>JavaScript date validation</title>
    <form id=”form1″ runat=”server”>
        <asp:TextBox ID=”txtDate” runat=”server”></asp:TextBox><br />
        <asp:Button ID=”btnValidate” runat=”server” Text=”Click to Validate” OnClientClick=”return validateDate();” />
Check the figure below for more information:
Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint 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 →