Disable Special Characters using JavaScripta

The script works in such a way that the TextBox will accept only alphabets, numbers i.e. alphanumeric values with some allowed special keys, this unless a special character key has been specified to be excluded it won’t be accepted. 

The RegularExpressionValidator control checks whether the value of an input control matches a pattern defined by a regular expression. This type of validation allows you to check for predictable sequences of characters, such as those in e-mail addresses, telephone numbers, and postal codes.

In this short article, I will explain how to restrict the user from entering special character in TextBox using JavaScript or, in other words, remove special characters from TextBox using JavaScript as user types into the TextBox.

you can find more code example at stupidcodes.com

Write a small JavaScript function
  1. function abc(value)   
  2. {  
  3.     var count = 0;  
  4.     var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";  
  5.     for (var i = 0; i < value.length; i++)   
  6.     {  
  7.         if (iChars.indexOf(value.charAt(i)) != -1)   
  8.         {  
  9.             count++;  
  10.         }  
  11.     }  
  12.     if (count > 0)   
  13.     {  
  14.         document.getElementById("btn").disabled = true;  
  15.     }  
  16.     else   
  17.     {  
  18.         document.getElementById("btn").disabled = false;  
  19.     }  
  20. }