public static bool IsSpecialCharacters(this string stringToTest) { const string charSet = "[^a-z0-9]"; //Regex RgxUrl = new Regex("[^a-z0-9]"); //blnContainsSpecialCharacters = RgxUrl.IsMatch(stringToCheck); return Regex.Match(stringToTest, @"^[" + charSet + @"]+$").Success; }
.ToString()
Contains
char
IndexOf
if (input.IndexOf(item) != -1) return true;
IndexOfAny
private static readonly char[] SpecialChars = { '\\', '|', '!', '#', '$', '%', '&', '/', '(', ')', '=', '?', '»', '«', '@', '£', '§', '€', '{', '}', '.', '-', ';', '\'', '<', '>', '_', ',', '*', '+' }; public static bool HasSpecialChar(string input) => input != null && input.IndexOfAny(SpecialChars) != -1;
return Regex.Match(stringToTest, @"^\W+$").Success;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)