Leap Year Date Validation in Javascript

Leap year date validation script, to validate the date and display the number of days in the given year.


  • The script displays the number of days in the given year.
  • Online script to validate whether the given year is a leap or not.
  • Checks a valid date format. i.e., Date given should be in mm/dd/yyyy or mm-dd-yyyy format.
  • Responsive and easy to integrate.


Enter Date [mm/dd/yyyy or mm-dd-yyyy format]



<!--Scripts by hscripts.com--><!--More scripts @ www.hscripts.com--><html> <head> <title>Validate Date and Leap year</title>
<script src='https://www.hscripts.com/js/jquery.js'></script> <style>
#output {
font-size:1.2em; font-weight:bold; color:green;
-moz-animation: sep-blinks 1s linear 0s infinite;
-webkit-animation: sep-blinks 1s linear 0s infinite;
animation: sep-blinks 1s linear 0s infinite; }
#output1 {
font-size:1.2em; font-weight:bold; color:red;
} .frms
margin:0 auto;
padding:10px; font-family:Tahoma, Geneva, sans-serif; color:#333; font-size:.9em; line-height:1.2em;
.frms input[type="text"]
{ width:59%; background:#fff;
border:#ddd 1px solid; border-radius:.35em; -moz-border-radius:.35em; -webkit-border-radius:.35em; -o-border-radius:.35em;
padding:0 .5%;
margin-top:5px; margin-bottom:15px; height:35px;
.frms input:hover
{ box-shadow:#dae1e5 0px 0px 5px; -moz-box-shadow:#dae1e5 0px 0px 5px; -webkit-box-shadow:#dae1e5 0px 0px 5px; -o-box-shadow:#dae1e5 0px 0px 5px; }
.frms input:focus {
-webkit-box-shadow: inset 7px 4px 7px -7px rgba(0,0,0,0.42);
-moz-box-shadow: inset 7px 4px 7px -7px rgba(0,0,0,0.42);
box-shadow: inset 7px 4px 7px -7px rgba(0,0,0,0.42); border:#9d9983 1px solid;
} .frms input[type="submit"] {
padding:7px 14px; font-weight:bold; color:#fff; cursor:pointer; border-radius:.3em; -moz-border-radius:.2em; -webkit-border-radius:.2em; -o-border-radius:.2em;
margin:10px 0;
border:none; background:#75ab22;
border-bottom:#629826 3px solid;
text-shadow:#396e12 1px 1px 0px;
} .resp_code
margin:5px 10px 10px 300px;
padding:10px 20px 10px 20px;
font:normal 1em/1.3em Tahoma, Geneva, sans-serif; color:#333; background:#f8f8f8;
border:#ddd 1px solid; border-radius:.25em; overflow:auto;width:50%;
} body {
background: #fff none repeat scroll 0 0;
color: #666;
font: 0.81em/150% Tahoma,Geneva,sans-serif; word-wrap: break-word;
} @media screen and (max-width: 480px) {
.resp_code{width:auto !important;margin:0px !important;}
} </style> </head> <body>
<div class='frms resp_code' align='center'> <b>Enter Date [mm/dd/yyyy or mm-dd-yyyy format]</b><br><br> <input type='text' name='text1' id='date' style='width:40%;' onkeyup="checnum(this)" maxlength=10/>
<input type="submit" name="submit" value="Submit" onclick="checkDate()"/>
<div id='output'></div><div id='output1'></div> <div
align='center' style="font-size: 10px;color: #dadada;" id="dumdiv">
<a href="https://www.hscripts.com" id="dum" style="font-size: 10px;color: #dadada;text-decoration:none;color: #dadada;">©h</a>
</body> <script>
var inputText = document.getElementById('date');
var dateformat = /^(?:(0[1-9]|1[012])[\- \/.](0[1-9]|[12][0-9]|3[01])[\- \/.](19|20)[0-9]{2})$/;
function checkDate()
if (inputText.value.match(dateformat))
var opera1 = inputText.value.split('/');
var opera2 = inputText.value.split('-');
lopera1 = opera1.length;
lopera2 = opera2.length;
if (lopera1>1)
{var pdate = inputText.value.split('/');}
else if (lopera2>1)
var pdate = inputText.value.split('-');}
var mm
= parseInt(pdate[0]);
var dd = parseInt(pdate[1]);
var yy = parseInt(pdate[2]);
if ( (!(yy % 4) && yy % 100) || !(yy % 400)){
result= "Year "+yy+" has 366 days and it is a Leap year ";
} else{
result= "Year "+yy+" has 365 days and it is Not a Leap year "; } document.getElementById('output1').innerHTML = ''; document.getElementById('output').innerHTML = result;
else{ document.getElementById('output1').innerHTML = 'Invalid date format!'; $('#output1').fadeIn(5000); $('#output1').fadeOut(5000); document.getElementById('output').innerHTML = ''; document.getElementById('date').value = ''; } } function checnum(obj)
var ch=obj.value;
var numreg = /^[0-9 \- \/]+$/;
if (ch.match(numreg)){}
else{ var df=ch.substring(0,(ch.length-1)); obj.value=df;
} </script></html><!--Scripts by hscripts.com-->
  • Release Date - 31-12-2015
  • Get free version without ©copyright link for just $10/-
  • For customization of this script or any script development, mail to support@hscripts.com


  • Copy-paste the code and run in the browser.
  • checkDate() function is used to validate leap year.
  • Use this script to check leap year entry in your webpages.


Related Scripts

Free Javascript Scripts

Ask Questions

Ask Question