要验证输入的内容是不是汉语,怎么写这个正则表达式

解决方案 »

  1.   

    匹配所有汉字的表达式:[\u0391-\uFFE5]
    楼主的例子:
    var s = '我们都是中国人';
    匹配“中国”的表达式:
    var preg = /^[\u0391-\uFFE5]+(中国)[\u0391-\uFFE5]+$/;
    if( preg.test(s) ) { //判断是否匹配
      alert('true');
      

  2.   

    /^([\x00-\x7F]|[\x80-\xFE][\x40-\x7E\x80-\xFE]){30}/
    这是汉字的正则 非汉字 !
      

  3.   

    http://topic.csdn.net/u/20100222/15/428bba9c-901d-49b4-8fa2-3f8817a196e0.html
      

  4.   

    try...String test = "测试";
    String reg = "^[\\u4e00-\\u9fa5]+$";
    Pattern pat = Pattern.compile(reg);
    Matcher m = pat.matcher(test);
    if(m.find())
    {
    System.out.println("全部是汉字!");
    }
    else
    {
    System.out.println("不全是汉字!");
    }
      

  5.   

    用native2ascii得到汉字的ascii码,然后用这些ascii码去匹配