Wednesday, 21 January 2015

How to Allow Numbers and Slash Validation in JavaScript

<script type="text/javascript">


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


         if (charCode == 47) 
{
             // Allow only 1  ('/')...
             if ((evt.value) && (evt.value.indexOf('/') >= 0))
                 return false;
            else
                 return true;
         }
         else if (charCode > 31 && (charCode < 48 || charCode > 57)) {
     
             return false;
         }
     }

 </script>

No comments:

Post a Comment