C# 正则验证 regcx.ismatch()非法字符验证

shuxiang0411 2012-09-06 02:27:06
C# 正则验证 regcx.ismatch()非法字符验证 非法字符包括 , . ? !
谁给写个后面的参数
...全文
409 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzz82103 2012-09-06
  • 打赏
  • 举报
回复
手抖点快了。。

Regex regex = new Regex(@"^([,.?!]?)$"));
if(!regex.IsMatch("你的字符串"))
{
//你的操作
}
zzz82103 2012-09-06
  • 打赏
  • 举报
回复


shuxiang0411 2012-09-06
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
[, . ? ! ]+
[/Quote]
regcx.ismatch(str,"[, . ? ! ]+")
zzz82103 2012-09-06
  • 打赏
  • 举报
回复

/// <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;
}
haiyun141 2012-09-06
  • 打赏
  • 举报
回复
没看懂问题,后面的参数?什么东东
bdmh 2012-09-06
  • 打赏
  • 举报
回复
[, . ? ! ]+

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧