Articles General Category JavaScript Style & Scripts

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>

You Might Also Like...

No Comments

    Leave a Reply

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