Check the validation which allows only didgits & hyphen

  1. <html>  
  2.    <head>  
  3.       <title>Sample Code</title>  
  4.       <script type="text/javascript">  
  5.       function Check(b)   
  6.       {  
  7.         var a = /(^[0-9]+[-]*[0-9]+$)/;  
  8.         if (a.test(b) == true)   
  9.         {  
  10.             alert("Match Criteria")  
  11.         }   
  12.         else   
  13.         {  
  14.             alert("Please Enter Only Digits & Hyphen.")  
  15.         }  
  16.      };  
  17.      </script>  
  18.    </head>  
  19.    <body bgcolor=#00ff00 alink=blue vlink=blue>  
  20.       <FORM name="windowEvent">  
  21.          Number : <input type="text" name="txtnumber" />  
  22.          <input type="button" value="Check" name="btnNumber" onClick="Check(txtnumber.value)" />  
  23.       </FORM>  
  24.    </body>  
  25. </html>