在vs2003里的textbox中怎么验证只能输入中文,不能输入特殊符号

解决方案 »

  1.   

     private  bool IsCh(string str)
            {
                Regex re = new Regex("^[\u4e00-\u9fa5]+$");
                return re.IsMatch(str);
            }
      

  2.   

    function()

       var reg = /^[\u4E00-\u9FA5]+$/; 
        if(!reg.test(this)){ 
            return false; 
        } 
         return true; 
      

  3.   

    添加TextBox控件的TextChanged事件,代码如下void TextBox1_TextChanged(object sender, EventArgs e)
    {
        int nSel = TextBox1.SelectionStart;
        TextBox1.Text = System.Text.RegularExpressions.Regex.Replace(TextBox1.Text,@"[^\u4E00-\u9FA5]", string.Empty);
        TextBox1.SelectionStart = nSel;
    }
      

  4.   

    <script>
    function onlyNumber(e)
                   {
                      var isIE = document.all?true:false;
                      var key;
                      if(isIE)
                      {         
                         key = window.event.keyCode;
                      }
                      else
                      {
                         key=e.which;        
                      }
                      if((key > 57 || key < 48)&& key != 8 && key != 12 && key!=127 )
                            return false;
                      else
                        {
                            return true;
                            }
                   }
                </script>文本框里面这样写
    <asp:TextBox ID="txtCount"  runat="server" onkeypress="return onlyNumber(event)">1</asp:TextBox>“这个是除了数字以外。其他东西都不能填进去的”。我想关键就是key的值了。自己试试改key的值吧。我没时间去试。你自己琢磨吧!!希望对你有帮助。
      

  5.   

    onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))" 
      

  6.   

    用正则表达式/[^\u4E00-\u9FA5]/g
    g代表的是全局的!