Wednesday, 21 January 2015

How to allow the asp TextBox only Date Format by using JavaScript ?

<script type="text/javascript">


function validateDate(input)
{
   //Basic check for format validity
    var validformat=/^\d{1,2}\/\d{1,2}\/\d{4}$/     
   
    if (!validformat.test(input.value))
    {
    alert('Enter the correct Date Format');
      input.value="";
        return false ;
      }


}

    onkeypress="return DateValidations();"


function DateValidations(evt) {
         var e = event || evt; // for trans-browser compatibility
         var charCode = e.which || e.keyCode;


         if (charCode > 31 && (charCode < 47 || charCode > 57))
           {
             return false;
             }
          else{
         return true;
         }
     }
</script>


In Code Behind: 


onchange="return  validateDate(this);"

No comments:

Post a Comment