日期:2014-05-18  浏览次数:20834 次

紧急!!偶写了一个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]+