通过javascript判断
//函数名:fucPWDchk
//功能介绍:检查是否含有非数字或字母
//参数说明:要检查的字符串
//返回值:0:含有 1:全部为数字或字母
function fucPWDchk(str)
{
  var strSource ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var ch;
  var i;
  var temp;
  
  for (i=0;i<=(str.length-1);i++)
  {
  
    ch = str.charAt(i);
    temp = strSource.indexOf(ch);
    if (temp==-1) 
    {
     return 0;
    }
  }
  if (strSource.indexOf(ch)==-1)
  {
    return 0;
  }
  else
  {
    return 1;
  } 
}function jtrim(str)
{     while (str.charAt(0)==" ")
          {str=str.substr(1);}      
     while (str.charAt(str.length-1)==" ")
         {str=str.substr(0,str.length-1);}
     return(str);
}

解决方案 »

  1.   

    Private Function TestChinese(ByVal StrChinese As String) As Integer
            Dim Bool As Integer = 0
            Try
                Dim StrLength As Integer = StrChinese.Length
                Dim MyStrLength As Integer = System.Text.Encoding.Default.GetBytes(StrChinese).Length
                If StrLength <> 0 Then
                    If StrLength < MyStrLength Then
                        If StrLength * 2 = MyStrLength Then
                            '全是中文
                            Bool = 1
                            Return Bool
                        Else
                            '包含中英 
                            Bool = 2
                            Return Bool
                        End If
                    Else
                        '全部英文
                        Bool = 3
                        Return Bool
                    End If
                End If
            Catch es As Exception
                Trace.WriteLine("error at testchinese " & es.ToString)
                Return Bool
            End Try
        End Function
      

  2.   

    http://expert.csdn.net/Expert/topic/2770/2770853.xml?temp=.7881128
    http://expert.csdn.net/Expert/topic/2799/2799163.xml?temp=.7102472
    要搜索里搜“汉字”,你会查到很多方法。。
      

  3.   

    判断asci码,可以区分。论坛里这样的文章很多,楼主搜索下就有了。
      

  4.   

    //System.String type encoded by UNICODE ,not ASCII codestring s = "hello你好";
    for(int i = 0;i<s.Length,i++)
     {
       if((s[i]>'a' && s[i]<'z') || (s[i]>'A' && s[i]<'Z' ))
          {System.Console.WriteLind("s["+{0}+"] is a English Letter",i}
     }
      

  5.   

    to smartcreater()
        你这方法没有一般性,如果string s="/ \.你好";呢?
        或者是一些ascii码32以下的字符呢?用你这就不能判断了!
      

  6.   

    首先谢谢大家的鼎立帮助!smartcreater(),也很感谢你的方法。早上很着急,提问的时候也没有把问题描述得很清楚。不好意思!是这样的,我现在要根据TextBox中的字符类型(用户输入),来判断该给处理业务的函数传什么名称的参数,所以先要判断TextBox中的字符类型,而且它只能为汉字与英文字母中的一种,即不能又包含汉字也包含英文字母。你的方法我想过,就是不太清楚当字符为汉字的时候对字符串长度是如何处理的,还是一个汉字就是一个长度吗?这个我还不清楚,等下试一下。谢谢你!
      

  7.   

    只匹配中文 ^[\u4E00-\u9FA5]*$
      

  8.   

    在.net中System.String 与System.Char 都是用unicode编码,不管是中文还是英文还是任何其他语言及符号 一个字符占2个bytes
    字符串的长度只表示字符的数量,与编码无关。如果你要判断是不是中文,应该用内码比较