Check For Special Characters using RegularExpressions.

Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 191
Check for special characters in the passed string If special character is found returns True else False.
We will use IsMatch method of RegularExpressions class.
Using System.Text.RegularExpressions;
public bool CheckForSpecialChars(string Param)
bool Return = false;
Regex lrexRe = new Regex("[0-9!@#$%&()+-=]");
if (lrexRe.IsMatch(Param))
Return = true;
return Return;

bool is_special_chars1 = CheckForSpecialChars("vishal#neeraj&#$JKKKN$%&**()"); //true
bool is_special_chars2 = CheckForSpecialChars("vishalneeraj"); //false

Comments or Responses

Login to post response