A two line code in C# to remove any invalid character from input string. Very handy to clean input data from a form
\\C#
String CleanInput(string input)
{
//replace invalid character with empty string (other than alpanumeric,.,@ and -)
return Regex.Replace(input,@"[^\W\.@-]","");
}
\\C#
String CleanInput(string input)
{
//replace invalid character with empty string (other than alpanumeric,.,@ and -)
return Regex.Replace(input,@"[^\W\.@-]","");
}
Comments