首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

紧急偶写了一个c#正则表达式判断语句,不知道为什么不对,高手快进,

2012-02-29 
紧急!!偶写了一个c#正则表达式判断语句,不知道为什么不对,高手快进,在线等!!判断textbox里输入的必须为汉

紧急!!偶写了一个c#正则表达式判断语句,不知道为什么不对,高手快进,在线等!!
判断textbox里输入的必须为汉字,点击提交按钮时检查。
string textPattern = "^[u4e00-u9fa5],{0,}$";

  System.Text.RegularExpressions.Regex reg = new Regex(textPattern);
  string textInput = this.textBox1.Text;
   
  bool match = Regex.IsMatch(textInput, textPattern);
  if (match)

  MessageBox.Show(" is right.");
  else
  MessageBox.Show("is not right.");
高说快看看问题出在了哪,为什么不管输入的正不正确都不执行MessageBox.Show(" is right.")!!急需得到答案!!


[解决办法]
string textPattern = "^[u4e00-u9fa5]+$";
 string textInput = this.textBox1.Text; 

if (System.Text.RegularExpressions.Regex.IsMatch(textInput, textPattern)
{
MessageBox.Show("no!");
}
else
{ MessageBox.Show("right"); }
[解决办法]
string textPattern = "^[u4e00-u9fa5],{0,}$ "; 

System.Text.RegularExpressions.Regex reg = new Regex(textPattern); 
string textInput = this.textBox1.Text; 

bool match = Regex.IsMatch(textInput, textPattern); 
if (match) 

MessageBox.Show( " is right. "); 
else 
MessageBox.Show( "is not right. "); 
高说快看看问题出在了哪,为什么不管输入的正不正确都不执行MessageBox.Show( " is right. ")!!急需得到答案!! 
------------------------------------
楼主正则式本身就是错误
[解决办法]
只能输入汉字:“^[\u4e00-\u9fa5],{0,}$”


[解决办法]
有没有高手知道只能输入中文的正则表达式?我的只能判断第一个字符,后面的旧判断不了了!!唔~~~~
----------------------------

C# code
[\u4E00-\u9FA5]+ 

热点排行