Simple JavaScript validation for dates

In this post i would like to explain about Simple JavaScript date validation.  We can  check dates with individual drop down boxes for day, month and year. In the validation part we have to check with first year , next  month and next day. In this we may not get the correct validations.

Simple JavaScript validation for dates | Anil Labs

Simple JavaScript validation for dates | Anil Labs

For this below function is very useful to do the validations for dates.

<script>
  function datechecking(){
   var before=new Date();
   before.setFullYear(2011,8,30); // members before spet 30
   var upto=new Date();
   upto.setFullYear(2011,9,15); // members before oct 15
   var today = new Date();
  }
</script>

First create an object to Date(). And set the date which we don’t want to register before and set the date which don’t want to register after some date. And assign today date.
Below conditions to check before and after statements.

<script>
 if(today <= before){
   alert("before statement");
 }else if(today <= upto){
  alert("after statement");
 }  
</script>

Anil Kumar Panigrahi

With more than 10 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.