Wednesday, August 3, 2016

How to find whether a string contains any of the special characters?

 Regex RgxUrl = new Regex("[^a-z0-9]");
                    blnContainsSpecialCharacters = RgxUrl.IsMatch(stringToCheck);
========================================================
public static bool IsSpecialCharacters(this string stringToTest)
       {
           //const string charSet = "[^a-z0-9]";
             const string charSet = "[^a-zA-Z0-9]";

           //Regex RgxUrl = new Regex("[^a-z0-9]");
           //blnContainsSpecialCharacters = RgxUrl.IsMatch(stringToCheck);

           return Regex.Match(stringToTest, @"^[" + charSet + @"]+$").Success;
       }