Subin Thomas

Subin Thomas

  • NA
  • 4.9k
  • 125.9k

javascript to avoid special characters ?

Jan 22 2020 3:11 PM
i want to write a javascript code to avoid special characters in the textbox but,
it should allow  comma , round brackets and forward slash 
 
below is the javascript code which i have used it avoid all the special characters
  1. <script type="text/javascript">  // added by subin to block special characters    
  2.    function blockSpecialChar(e){    
  3.        var k;    
  4.        document.all ? k = e.keyCode : k = e.which;    
  5.        return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));    
  6.        }    
  7. </script>
 

Answers (3)