Created
October 30, 2015 18:03
-
-
Save jdowd7/e611dcea6482aac1727f to your computer and use it in GitHub Desktop.
Checks to see if a string contains a special character
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ValidationResult ContainsSpecChar(string sampleStr) | |
{ | |
Regex specChar = new Regex(@"[^A-Za-z0-9!?.&,\ -]", RegexOptions.IgnorePatternWhitespace); | |
MatchCollection matches = specChar.Matches(sampleStr); | |
if (matches.Count > 0) | |
{ | |
return new ValidationResult("Message cannot contain special characters."); | |
} | |
return ValidationResult.Success; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment