需求:
   1、str是一堆字符串(包括中文和一些特殊字符 ~!@#¥&*这些东西等等)
   2、一个中文占6个字符 
   3、超过32个字符 即给出错误提示
   
问:如何校验,请给出较简洁的实现,谢谢各位。

解决方案 »

  1.   

    var length = str.replace(/[^\x00-\xff]/g,"******").length; 
    if (length>32) alert("error");
      

  2.   

    只是说明,不改很简单呵
    var temp = str.replace(/[^\x00-\xff]/g,"******");
    var length = temp.length; 
    if (length>32) alert("error");
      

  3.   

    其实用temp都没必要,没有赋值,仅仅调用replace是不会修改原字符串的,只是返回一个新字符串而已