111,092
社区成员




Regex regex = new Regex(@"^([,.?!]?)$"));
if(!regex.IsMatch("你的字符串"))
{
//你的操作
}
/// <summary>
/// 过滤字符
/// </summary>
public static string Filter(string sInput)
{
if (sInput == null || sInput.Trim() == string.Empty)
return null;
string sInput1 = sInput.ToLower();
string output = sInput;
string pattern = @",|.|?|!";
if (Regex.Match(sInput1, Regex.Escape(pattern), RegexOptions.Compiled | RegexOptions.IgnoreCase).Success)
{
throw new Exception("字符串中含有非法字符!");
}
else
{
output = output.Replace("'", "''");
}
return output;
}