2009/03/06

A simple way to check special characters by using Regex

using System.Text.RegularExpressions;

public static string CheckString(string text)
{
  Regex oRegex = new Regex(@"[<;/>]+", RegexOptions.IgnoreCase);
  Match oMatch = oRegex.Match(text);
  oRegex = null;

  if (oMatch.Success)
    return "Please do not input any HTML tag";
  else
    return "";
}
Put any character that you want to check inside the "[]".

No comments:

Post a Comment