Regex to Replace All Special Characters from String Asp.Net C#

Regex to Replace All Special Characters from String Asp.Net C#

In this tutorial i will explain how to use REGEX (Regular Expression) to remove special characters from a string, or Regex to Replace All Special Characters from String Asp.Net C#. I am using this for all my TEXTBOX’s, because it is a prevention of SQL injection.

In earlier post we have discussed about CheckBoxList Validation Using JavaScript In Asp.NetValidation Summary Show Message Box Only, NO Display SummaryHTML5 AJAX Responsive Contact Form With Google Maps and How to Edit Excel File with Multiple Users.

 string str = search.Text;
 string replaceschar = Regex.Replace(str, "[^a-zA-Z0-9_]+", " ");
 hdnsrch.Value = replaceschar;