Skip to content

Instantly share code, notes, and snippets.

@jdowd7
Created October 30, 2015 18:05
Show Gist options
  • Save jdowd7/886adfed6fda34c9aec1 to your computer and use it in GitHub Desktop.
Save jdowd7/886adfed6fda34c9aec1 to your computer and use it in GitHub Desktop.
Check for XML encoded chars
public static ValidationResult EscapedAmpersand(string sampleStr)
{
Regex specChar = new Regex(@"&(?!(?:apos|quot|[A-Za-z0-1!?.,\ -]|amp);|#)", RegexOptions.IgnoreCase);
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