原代码是:
function getlengthB(str)
{ return str.replace(/[" "^\x00-\xff\]/g,"").length;
}
function Checkdata()
{
document.getElementById("titlestr").innerHTML="";
document.getElementById("constr").innerHTML="";
       
ischeck=true
        CheckUbbUse('UserName',1,document.getElementById('Body').value)//定员帖检查
if (getlengthB(document.Dvform.topic.value)<3 && ispostnew==1)
{
document.getElementById("titlestr").innerHTML=" <font color=\"#FF0000\">←您忘记填写标题</font>"
document.Dvform.topic.focus();
ischeck=false
}
想在getlengthB函数中增加去掉空格的命令

解决方案 »

  1.   

    function getlengthB(str)
    { return str.replace(/\s/g,"").replace(/[" "^\x00-\xff\]/g,"").length;
    }
      

  2.   

    replace(/(^\s*)|(\s*$)/g, "");
    试试~~~~~~~~~~·
      

  3.   

    [" "^\x00-\xff\]你这写的是什么?本身就是语法错误的,再者里面含义也特别乱!
      

  4.   

    function getlengthB(str)
    { return str.replace(/[^\x00-\xff]/g,"").length;
    }
    这个函数加入去除空格的功能
      

  5.   

    str.replace(/[" "^\x00-\xff\]/g,"").replace(/\s/g,"").length
      

  6.   

    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    ※以下是引用楼主 linhongsha() 在2007-7-13 10:54:53 的发言:
    ──────────────────────────────────────────
    function getlengthB(str)
    { return str.replace(/[^\x00-\xff]/g,"").length;
    }
    这个函数加入去除空格的功能
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    function getlengthB(str)
    {
        return str.replace(/[\u0100-\uffff ]/g,"").length;
    }
      

  7.   

    function getlengthB(str)
    {
        return str.replace(/[\u0100-\uffff ]+/g,"").length;
    }这样写效率会高一点点
      

  8.   

    [ ]就可以了,不用双引号。楼主你的表达确实容易让人误解。你试一下
    function getlengthB(str)
    {
        return str.replace(/[\u0100-\uffff ]+/g,"").length;
    }
    已经达到你的要求了,注意\u0100-\uffff后面有一个空格的。