有关正则表达式的运用

bethrezen 2003-04-18 01:57:32
如果:
string strr= textBox1.Text.ToString();
那该怎样判断strr只能输入"," "0-9" "/" ? 而且strr只能以数字开头和结尾.

...全文
50 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bethrezen 2003-04-18
  • 打赏
  • 举报
回复
E:\work\Menu\Hscount.cs(176): Method 'System.Text.RegularExpressions.Regex.IsMatch(string, string)' referenced without parentheses
E:\work\Menu\Hscount.cs(178): Operator '&&' cannot be applied to operands of type 'System.Text.RegularExpressions.Match' and 'System.Text.RegularExpressions.Match'
_甲壳虫 2003-04-18
  • 打赏
  • 举报
回复
在winform中的处理:
string aa=@"[^0-9,/]";
System.Text .RegularExpressions .Regex rg_temp=new System .Text .RegularExpressions .Regex (aa);
bool tt=rg_temp.IsMatch (strr);
if(rg_temp.IsMatch ==true)
{
if(new System .Text .RegularExpressions .Regex ("[0-9]").Match (strr,0,1)&&new System .Text .RegularExpressions .Regex ("[0-9]").Match (strr,strr.Length-1,1))
{
正确处理
}
else
{
错误处理
}
}
else
{
错误处理
}
spring_ok 2003-04-18
  • 打赏
  • 举报
回复
^\d+([\d,/]*\d$
_甲壳虫 2003-04-18
  • 打赏
  • 举报
回复
控件:
<asp:RegularExpressionValidator id="aa" ControlToValidate="TextBox1" ValidationExpression="\d+(([0-9,/]{1,})?\d{1,})?" Runat="server" ErrorMessage="tt"></asp:RegularExpressionValidator>
bethrezen 2003-04-18
  • 打赏
  • 举报
回复
不行啊!运行后有12个error!
_甲壳虫 2003-04-18
  • 打赏
  • 举报
回复
strr=strr.replace(/[^0-9,/]/gi,'')
可判断strr只能输入"," "0-9" "/"
利用控件:

111,093

社区成员

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

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

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