Stopping the registarion on invalid input:JavaScript
<p>I have a registration form with date of birth as one of the fields, I have written a function for future date which has to be invalid. But when the user puts a future date it still submits the form, although alert is being made to the user.</p>

<p>This is the function for alert, and its working fine.</p>

<pre><code>var user_birth_year=document.getElementById("birth_year").value;
var user_birth_month=document.getElementById("birth_month").value;
var user_birth_day=document.getElementById("birth_day").value;

var userDate = new Date(user_birth_year,user_birth_month-1,user_birth_day);

var currentDate = new Date();
var res="Invalid date";
if(currentDate.getTime() &lt; userDate.getTime() ) {
  document.getElementById('registererror').innerHTML = "&lt;span class='errorMsg'&gt;"+res+"&lt;/span&gt;";
  document.getElementById('registererror').style.display = 'block';
} else {
  document.getElementById('registererror').style.display = 'none';
}
</code></pre>
